This 2017 video from the USA is called 10 Egyptian Gods and Their Origins.
Over 5,000 years ago, the area which is now the Libyan desert became drier and drier. This made it impossible for the hunter-gatherer people living there to continue their old ways of life. They moved to the Nile river valley, starting a new economic, Neolithic, later Bronze Age, later Iron Age, system of cattle raising, agriculture and handicraft. The surplus produced there was appropriated by a new ruling class. Instead of the equality of small hunter-gatherer bands, there came country-wide royal dynasties and their ministers, high priests, priests, commoners and slaves.
The non-ruling majority might have risen up in revolt if the ruling class would have told poor peasants: We have better food, better housing, etc. than you, just because we feel like it and we like grinding you down. No, there came a different ideology: in heaven, in the underworld, in invisible worlds, there are gods determining the rules on earth. The representative of these gods on earth is the king, the pharaoh. The pharaoh, in turn, appoints priests all over Egypt to represent him. A revolt against the priests and the pharaoh would not be just a revolt against fellow humans. It would be a revolt against men of the Gods. The gods would punish such a revolt terribly.
This is not just about ancient Egypt. Similar things happened in other ancient societies in many countries.
From Nature, 20 March 2019:
Complex societies precede moralizing gods throughout world history
The origins of religion and of complex societies represent evolutionary puzzles1,2,3,4,5,6,7,8. The ‘moralizing gods’ hypothesis offers a solution to both puzzles by proposing that belief in morally concerned supernatural agents culturally evolved to facilitate cooperation among strangers in large-scale societies9,10,11,12,13. Although previous research has suggested an association between the presence of moralizing gods and social complexity3,6,7,9,10,11,12,13,14,15,16,17,18, the relationship between the two is disputed9,10,11,12,13,19,20,21,22,23,24, and attempts to establish causality have been hampered by limitations in the availability of detailed global longitudinal data. To overcome these limitations, here we systematically coded records from 414 societies that span the past 10,000 years from 30 regions around the world, using 51 measures of social complexity and 4 measures of supernatural enforcement of morality. Our analyses not only confirm the association between moralizing gods and social complexity, but also reveal that moralizing gods follow—rather than precede—large increases in social complexity. Contrary to previous predictions9,12,16,18, powerful moralizing ‘big gods’ and prosocial supernatural punishment tend to appear only after the emergence of ‘megasocieties’ with populations of more than around one million people. Moralizing gods are not a prerequisite for the evolution of social complexity, but they may help to sustain and expand complex multi-ethnic empires after they have become established.
Belgian (Roman Catholic) daily De Standaard writes on this research (translated), 25 March 2019:
Rules first, then gods to supervise
God only sees us when we are many
Which came first: the advanced human civilization or the almighty god? It is a question that scientists studying the origins of civilizations and religions have been thinking about for some time. Did people first start living together and then gods were created to keep everyone in line, or were those punishing gods there first and did people then develop a society to serve them?
A team of researchers from ten different countries says they have found the answer to that question: complex civilizations precede the emergence of gods who oversee the rules. The researchers come to this conclusion after studying 414 different civilizations, which have existed for 10,000 years in thirty regions around the world. …
Karma in Buddhism
Many scientists endorse the hypothesis that social cohesion and harmony in beginning states requires a moralizing god or supernatural punishment. An example of the first phenomenon is the god of the Old Testament, who prescribes people what to do and punishes them if they break the rules. Think of Sodom and Gomorrah. The principle of karma in Buddhism is an example of the second phenomenon: those who misbehave are presented with the bill in this life or the next. The idea is that without this kind of supervision from above, people would be less inclined to abide by the rules that made a society livable.
Dear Roman Catholic Belgian daily: rules making a society livable for everyone? Or making it especially livable for privileged ruling people?
The researchers conclude that this almost always happens after a state has developed into a “mega society” with more than a million inhabitants. The first moralizing god they encountered was Maät, who appeared in Egypt around 2800 BC. This was followed, eg, by Shamash (around 2200 BC in Mesopotamia) and Ahura Mazda (around 500 BC in Persia). Of the societies that did not develop a moralizing god, only the empire of the Incas succeeded in reaching the milestone of a million inhabitants, without subsequently having another moralizing god. It seems, therefore, that such gods are not a condition for the emergence of a great empire, but that they are necessary to hold such an empire together.