Why does a car leak oil only immediately after it is shut off?

If at the back of the oil pan it is the rear main bearing seal - fairly expensive & always leaks after car is shut off. Otherwise basic reason is all oil in engine runns down to lowest point the oil pan