The emergence of religion has long been explained as a result of either culture or environmental factors but not both.
The new findings imply that complex practices and characteristics thought to be exclusive to humans arose from a medley of ecological, historical, and cultural variables.
Where previous research relied on rough estimates of ecological conditions, this study used high-resolution global datasets for variables such as plant growth, rain and temperature.
The team also used data from the Ethnographic Atlas, an electronic database of more than a thousand societies from the 20th century.
"A lot of evolutionists have been busy trying to bang religion on the head but I think the challenge is to explain it," Professor Gray said.
"Although some aspects of religion appear maladaptive, the near universal presence of religion suggests that there has to be some adaptive value and by looking at how these things vary ecologically, we get some insight."
Further, the researchers found a strong correlation between belief in high gods who enforce a moral code and other societal characteristics.
Political complexity -- namely a social hierarchy beyond the local community -- and the practice of animal husbandry were both strongly associated with a belief in moralising gods.
"Previous studies have pointed to religion being a force for building strong social groups but there has, until now, been no systematic global test of the social bonding hypothesis," said fellow co-author Dr Joseph Bulbulia, from Victoria University of Wellington.
While there had been studies showing that natural calamities are associated with religious conversion - including one involving Dr Bulbulia carried out in Christchurch after the earthquake - he said overall the extent to which ecology shaped religion around the world remained fascinatingly unclear.
The study's primary author Dr Carlos Botero, an evolutionary ecologist from the Initiative for Biological Complexity at North Caroline State University, saw the study as "the tip of the iceberg" in examining human behaviour from a cross-disciplinary standpoint.
Dr Bulbulia also saw the research as a "blueprint" for such a research approach to the area.
"We think we find an association between religion, climate, and political complexity because religion fosters strong social bonds which help people to co-operate," he said.
"Such bonds are especially important in harsh/unpredictable environments."
However, the dark side of highly-united social groups was intergroup violence, he said.
"In future work, we hope to better understand the factors that link religion in some regions of the world with peace, and in other regions of the world with violence."
The work was supported by the Royal Society of New Zealand Marsden Fund and the National Evolutionary Synthesis Centre, a non-profit science centre based at Duke University at the University of North Carolina, Chapel Hill.