I believe that religion started as science and philosophy and government.
As "science," it explained the things that couldn't be explained, such as why the sun disappeared below the horizon each night, or how the earth was formed or why there were floods and droughts.
As "philosophy," it explained right from wrong, and tried to identify the role of human beings within their families, their communities, within the known world, and within what they understood of the universe. It attempted to answer the "whys."
As "government," it provided rules to live by, and consequences for breaking those rules. If your goat eats your neighbor's crops, you've gotta give him a few shekels. If you steal, the community cuts off your hand. Or if you steal, you will be a lowly lifeform in your next life. So don't do it.
Every society has created religion. There were different stories and different answers to the big questions and different rules. But now we have real science. Philosophy continues to ask increasingly complex questions, without needing to take a diety into account. And we as a species are trying to create just governments. Maybe we haven't gotten it quite right yet. But we are trying.