"For we know Him who said, 'And I will execute great vengeance upon them with furious rebukes; and they shall know that I am the Lord, when I shall lay my vengeance upon them.'" Ezekiel 25:17.

The God depicted in the Old Testament may sometimes seem wrathful. And in that, he's not alone; supernatural forces that punish evil play a central role in many modern religions.

But which came first: complex societies or the belief in a punishing god?

A new study suggests that the formation of complex societies came first and that the beliefs in such gods helped unite people under a common higher power.

Ancient societies often used supernatural forces to explain natural phenomena, such as lightning. But in the past several millennia, religions also used supernatural forces to enforce moral codes. For example, the Egyptian sun god, Ra, judged the fate of people in the afterlife according to how well they followed the code of "maat," or "what is right." [The World's Top Religions (Infographic)]

Past work suggested that the rise of this idea of cosmic enforcement of morality was associated with social complexity. The concept of supernatural judgment evolved to help strangers in large societies cooperate, researchers hypothesized. Some work, such as analyses of Austronesian religions or of the Viking age in Scandinavia, suggested that moralizing gods preceded complex societies, while other research, such as a study of Eurasian empires, found that moralizing gods followed the rise of complex societies.

But those studies were limited in geographic scope and hampered, at times, because historians lacked detailed information on the complexity of societies at given points in history, said Patrick Savage, an anthropologist at Keio University in Kanagawa, Japan. In the new study, Savage and his colleagues sought to overcome these limitations using the Seshat: Global History Databank, a database of information about global history from the end of the Paleolithic period up to the Industrial Revolution.

The scientists analyzed the relationship between social complexity and moralizing gods in 414 societies spanning the past 10,000 years from 30 regions across the globe. Researchers examined 51 measures of social complexity, such as the size of the largest settlement and the presence of a formal legal code, and four measures of supernatural enforcement of morality, such as the concept of a supernatural force that monitors and punishes selfish actions.

The researchers found that belief in moralizing gods usually followed increases in social complexity, generally appearing after the emergence of civilizations with populations of more than about 1 million people.

"It was particularly striking how consistent it was [that] this phenomenon emerged at the million-person level," Savage said. "First, you get big societies, and these beliefs then come."

All in all, "our research suggests that religion is playing a functional role throughout world history, helping stabilize societies and people cooperate overall," Savage said. "In really small societies, like very small groups of hunter-gatherers, everyone knows everyone else, and everyone's keeping an eye on everyone else to make sure they're behaving well. Bigger societies are more anonymous, so you might not know who to trust."

At those sizes, you see the rise of beliefs in an all-powerful, supernatural person watching and keeping things under control, Savage added.

"We are not saying anything about the value of religion," Savage added. "We are not saying it is good or bad, but we are saying it has a deep and consistent relationship with societies throughout world history. Religion is deeply intertwined with what it means to be human, for better and for worse."

The scientists detailed their findings online today (March 20) in the journal Nature. Their work was supported in part by a grant from the John Templeton Foundation.

Originally published on Live Science.