The oil and gas in the earth today were formed many millions of years ago, long before humans appeared on the scene. Therefore, man can only theorize about the origin of these fossil fuels.
The most widely accepted theory is that the oil and gas found in the earth today had their beginnings in decomposed animals and plants. The decomposition was caused by bacteria and chemicals called enzymes which digested the plant and animal bodies.
Turner, George M., "Energy in Agriculture: Energy Resource Series for Youth and Adult Energy Programs: 3. Oil and Gas" (1981). Agricultural Engineering Energy Series. 11.