As covered previously, oil forms after organic material is subjected to high pressures and high temperatures for millions of years with a lack of oxygen - the organic material is usually plankton or algae, which live in the sea or lakes. But you'll have observed that a lot of oil is found inland, in places that you don't associate with the sea, like Texas, or Saudi Arabia.
The surface of the earth is composed of a number of tectonic plates, which float on top of the semi-molten mantle. These tectonic plates are constantly moving - if they collide then one plate might go under the other and melt, and cause volcanoes to rise, or if neither slides under the other and they keep on pushing then they'll create mountain ranges. If they slide across each other there'll be big earthquakes (like the San Andreas fault in California where two plates are sliding laterally), and if they diverge (move apart) then there'll be deep trenches, like the Marianas trench in the Pacific.
When our tiny sea creatures died tens or hundreds of millions of years ago the earth looked very different. Places that are now land were once the bottom of oceans (there are lots of places that are far inland and high up, where the fossils of shells and see creatures can be found - google 'inland sea fossils'), and ocean bottoms now were once the highest of mountains (see 'Extra', below).
You would think, too, that, since oil is formed from the corpses of small water dwellers, there would be lots of oil wells in the middle of the ocean, but look at a map of oil production and this is not the case. The bottom of the ocean is the oceanic shelf - it's relatively thin, compared to the continental shelves that land is made from, and the oceanic shelf is newer [look again at a satellite map - see the big white line down the middle of the Atlantic? This is the Mid-Atlantic Ridge - the longest mountain range in the world (though it's mainly under the ocean...). It marks the edge of two continental plates that are diverging, and is comprised of underwater valleys and volcanoes which spew fresh rock to fill in the gaps left by the diverging plates].
Instead the oil is found on continental shelves (see the white on the map), where run off from ancient rivers (old-time equivalent of the Nile, or the Amazon) has increased deposition of sediments, or the lives of countless quadrillions of plankton have been lived and lost in the middle of a large old lake, and settled to the bottom to be squeezed by wind-blown dust, and sand, and lava, and more dust.
It's not just the tectonic movement of plates that influences where oil is found - the climate, and its changes over millions of years, also has a huge effect. By watching the news you might think climate change or global warming is a recent phenomenon, but it has been ongoing since the mists of time (though the current issue is that it has been accelerated by our combustion of fossil fuels) - the last glacial period, during which nearly all of northern Europe and Canada were entirely covered by glaciers like Antarctica is today, ended only 15,000 years ago.
Take the Cretaceous period between 66 and 145 million years ago - it was relatively warm, and many continental shelves were covered by shallow seas. Life teemed in these warm, shallow seas (evidenced by the same creatures having formed much of the carbonates
In addition to these favourable conditions, there occur, throughout the history of the Earth, periodic 'anoxic events'. These happen every few hundred thousand years or so, and are periods during which the oxygen levels in portions of the sea become depleted - suspected to be caused by increased greenhouse gases, the slowing of ocean currents, and influxes of nutrients running off from the land.
So let's go back to the Cretaceous period - It was warm, so the land was covered in ultra-fertile jungle, and the organic run off from this provides the many shallow seas and lakes with nutrients, so the seas themselves are filled with life. An anoxic event occurs - maybe there's an exceptionally warm period, so more land based vegetation grows and increases the flow of nutrients to the seas and lakes: giant algal blooms appear, and consume the oxygen in the water (in the same way that fertiliser run-off from farms pollutes rivers and destroys fish by overfeeding the vegetation), and then the algae dies to fall to the sea or lake or river bed where there is even less oxygen. So we have lots of organic matter, and a lack of oxygen, and millions of years of sedimentation and burial to the high pressures and temperatures required for oil formation - it shouldn't be so surprising that oil forms, after all.