Okay. Bypassing abiogenic petroleum, which may or may not have a point but is scarcely a proven theory, let’s address the OP.
Since oil and even more natural gas rise, floating atop denser fluids like water, concentrations of them form at the top of arches in formations where stuff-that-generates-hydrocarbons are located. An impermeable caprock keeps them below itself; permeable rocks permit them to seep upwards through themselves until they hit the caprock.
But these areas where stuff-that-generates-hydrocarbons are located are themselves areas where organic matter has been concentrated. And to get that, we have to do an excursion into historical geology.
The crust of the Earth is made up of individual plates of various sizes, which effectively float on the mantle and are to some extent moved by currents in it. (This is a very broad and imprecise statement; the facts of the matter are substantially more complex, but it serves to provide a first-cut impression of what’s happening.)
Over tens of millions of years, these plates play a planet-scale game of bumper cars, colliding with each other, being drawn one under another, being replenished at midoceanic ridges, and so on. In areas where there is subsidence, there is a natural downward pull, and sediments tend to move toward such areas. Think of the Mississippi Valley – great parts of the soil of what was once Nebraska, Iowa, Illinois, Missouri, and such have now been carried downstream to be deposited in Mississippi and Louisiana. And such areas are conducive to heavy plant growth, which in turn dies and is buried and decays.
Carry this process on for millions of years, and you get sedimentary rock containing a lot of organic matter, deposited in thick layers, which continue to subside and have more layers laid down on top. This is what is called a geosyncline. They tend to form along the margins of continents, for what I think are obvious reasons. So what you have is a multi-state-sized dip in strata with more, thick strata piled on top. Eventually, this tends to “wrinkle” in folds under the pressure of moving plates and their interaction with neighboring plates.
Now, revert back to looking at the planet over a geologic time scale. Pieces slide around. What was a subtropical coast with multiple rivers depositing sediments in a geosyncline, has now moved somewhere else, and may well have butted up against another plate. For example, a large piece of Gondwanaland may have drifted north to abut loosely against western Eurasia – mostly, we call this piece “Africa.” But the Afric unit of Gondwanaland was not totally the present continent, and has been rifting apart under further tectonic stresses. Mostly, that tear is not complete, and constitutes the Great Rift Valley in Eastern Africa. But the north end of it did separate more completely, producing the Red Sea. And hence, the northeastern segment of “African Gondwanaland” is not geographically a part of that continent at all, but the Arabian Peninsula. And the area where it’s bumping into Eurasia is, of course, the Persian Gulf. Today, that’s a salt-water marginal sea surrounded by arid lands. But in Gondwanaland’s heyday, it was a tropical coast. And it has huge synclinal deposits, with a lot of buried organic matter.
You find oil and gas at the top of the upward folds within these former larger downward folds – geomorphologically, this is stated as “anticlines within a geosyncline.” And hence, as the northeast coast of Gondwanan Macro-Africa, now the east coast of Arabia, bumped into Asia, it folded, and anticlines formed in the geosynclinal rocks there – and the volatile fractions of the decayed organic matter in the geosyncline moved up into those anticlines, where they were trapped by the caprocks. Net result: concentrations of petroleum.
Likewise, North America at one time lay on the equator, which ran something like Yellowknife to New Orleans across the continent, with what’s now the East Coast south of it and the West Coast north. Some nice geosynclines formed in various places, including the Gulf Coast (in the tropics just south of the Equator), the strip from West Texas to Colorado and Alberta, and at the northeast tropical shore – what’s now the North Slope of Alaska. Over a couple hundred millions of years, the continent rotated counterclockwise and drifted north.
Same general explanation applies to nearly all the present oil and gas deposits. The oil shales and tar sands which kanicbird mentioned in the GD thread are such deposits in the early stages of formation. If not disturbed by us, 50 or 100 million years from now they will be oil-bearing strata.