The short answer
Religion did several jobs at once in ancient civilizations. It gave people explanations for things they could not control, supported the authority of rulers, held communities together through shared rituals, and tied into economic life through temples and festivals. Historians rarely point to a single reason. Ancient Mesopotamia shows all of these roles clearly, which makes it a useful example.
It explained what people could not control
Floods, droughts, plague and failed harvests were hard to predict. Many ancient societies treated the gods as the cause of such events and saw rituals as a way to restore their favor. In Mesopotamia, farming depended on the Tigris and Euphrates rivers, whose floods could be destructive and unpredictable. Religious practice was one way people responded to that uncertainty.
Religion also gave order to time. Festivals marked the seasons, and scholars linked to temples tracked the moon and stars to help set calendars. Scholars still debate what came before religion in early human communities, and how far back religious belief can be traced, since ancient evidence is hard to interpret.
It supported the authority of rulers
Rulers in many civilizations claimed divine approval. That claim made their orders seem legitimate and gave them a reason to fund temples and festivals. In Egypt, the pharaoh was seen as a link between the gods and the people. The Inca ruler claimed descent from the sun god Inti. In Mesopotamia, the stele carrying Hammurabi’s law code shows the king before the sun god Shamash, who was also the god of justice.
It held communities together
Shared festivals, processions and temple rituals gave people a common identity. A city’s patron god was a point of local pride, and religious rules about food, purity and burial set shared expectations. Festivals could also bring people from nearby farms into the city, linking rural and urban life.
It shaped economies and institutions
Temples often held land, animals and workers. In Mesopotamia, temples stored and distributed grain and goods, and writing developed partly to keep track of these resources. Religion gave these institutions legitimacy, because a temple’s economic work was framed as service to the god. In Egypt, the pyramids were built as royal tombs meant to secure the king’s passage into the afterlife, and their construction drew on large, organized work crews.
It shaped art, law and learning
Religious ideas inspired temples, statues, hymns and myths. Many early literary texts survive because scribes copied them, often in temple settings. Courts in several societies called on gods to witness oaths, which tied religion directly to justice.
Why the answer varies by civilization
Each civilization had its own gods, rituals and beliefs, so the role of religion varied by place and period. Some societies closely tied religion to state power, while others drew clearer lines between the two. Scholars debate how these roles worked in each case, so the answer for one civilization should not be assumed for another.
What the evidence can show
Most of what we know comes from buildings, art and writing. These sources usually reflect the views of rulers, priests and scribes, so they may tell us more about official religion than about everyday belief. Even so, they show how closely religion was tied to politics, work, law and the calendar in many ancient societies.