With due respect, I don't think the first two answers got at the heart of the matter. Keeping society stable is one reason why religion and theism are cross-cultural but independently of this we are already psychologically predisposed to supernaturalism. Even if we lived alone in the wilderness, lacking the need for morality because we'd only be looking after ourselves, we would still be inclined to believe in ghosts and spirits and deities and other things like that.

As the third responder noted, we are inclined towards theism because we tend to see agency and intention in everything. Why we are inclined to do that has an explanation in evolutionary psychology.

Children will often think in terms of agency and intention, and this carries into adulthood, although we shrug off a good deal of it through education. "Why are clouds for?" they might ask. "Clouds are for raining," they might answer. "Why do clouds rain sometimes and not others?" they may ask. "They only rain when they want to," would be the answer. Rainbows could be seen as a happy sky, and tornadoes as an angry sky. Even as adults we find it easier to understand something if we frame it in terms of intention, even if we know what's being talked about doesn't (or might not) have a mind with intention and foresight. Evolution shaped our minds to think in such terms.

Dinesh D'Souza thought it was improbable that religiousity/theism/supernaturalism would be an adaptative trait and, in a debate with Daniel Dennett, explained that, if a rabbit is being chased by a lion and the rabbit believes in the afterlife, it has no reason to fear the lion and may even desire death, making it unlikely to pass on its genes. However, his analogy does not work because very few human theists (jihadis and martyrs aside) would be for or indifferent to being killed and eaten by a lion.

The inclination to supernaturalism is adaptive in a Pascal's Wager sorta way. Hypothetically speaking, if you're a primitive hunter gatherer and you hear a slight rustling in the neaby bushes, it's possible that the rustling means a predator is hiding there, waiting to ambush and kill you. If you think there's a predator there, you can either be right and have saved your life, or you be wrong and mildly inconvienence yourself by expening the energy to run. On the other hand, if you think it's just the wind or a smaller animal that poses no threat, you can either be right and continue resting/loitering or be wrong and die (or be injured).

Those individuals who see predators in the bush more often then there are actually predators will generally live longer and have more chances to reproduce and individuals who see predators less often then they are really there.

This is one evolutionary explanation. There are others. You may want to look up Pascal Boyer's Religion Explained: The Evolutionary Origins of Religious Belief.