Religion was always a social tool first and foremost. Each major religion was introduced for its own reason, and popularized for a different reason.
Hinduism: Serves as a cultural achievement for ancient Indian kingdoms (especially the Kuru Kingdom around in Vedic times). Hinduism took elements from ancient Aryan (Indo-European) religions and codified them in writing, a way of proving the Indian kingdoms' mettle as culturally superior. It grew with elements like dharma and the caste system to be a tool for social stability to reinforce the idea of social hierarchy beyond mere mortal law.
Judaism: An identity for the ancient Hebrew tribes so that they would remain a people apart. A lot of the 10 Commandments and Levitical precepts were designed to insure social stability within the nation as well as to preserve unique Hebrew identity (a lot of the bans on different foods were because other surrounding nations ate those foods, or bans on incest because of the popular belief that the Egyptian royals practiced it). Arguably quite successful given that an ethnic group tracing heritage from the Hebrews is still here while most of their contemporaries are long gone, absorbed by the Arabs or Turks.
Taoism/Confucianism: Both introduced around the same time and both as answers to the problems of Zhou Dynasty era China, namely the infighting between different branch dynasties. Taoism introduced the focus on harmony and the Mandate of Heaven to try to quell the ambition of warlords and stop rebellion. Confucianism also focused on building a system of loyalty such that social rules would survive even when legal-political structures would break down and change.
Buddhism: A reaction to the more materialistic aspects of Hinduism. Buddha famously being inspired by the great poverty he witnessed around him and seeking an escape from drudgery, which the very cyclical and deterministic Hinduism seemed to encourage. Popularized ironically because it appealed to the wealthy and materialistic and the common man alike, and so was taken by the wealthy all around Asia but also rooted in the common people. Buddhism was popular because it was something you could practice rather than early religions which was just something that *was*, a goal to strive for rather than an immutable fact. In that sense it helped promote social stability because people could choose spirituality over, say, revolt.
Christianity: Originally a reaction to the legalistic nature of Judaism as shown in the Bible (particularly the Pharisees as written in the gospel). The nature of Judaism's purpose being a social glue, it did nothing to bring meaning to people's lives and the more moral parts of the Torah were de-emphasized in favor of the more legal ones. Worship of God wasn't about being good or just, it was just about doing or not doing certain things. Christianity filled a need in Jewish society to feel a connection with God. It was popularized because it was a good antidote to Greco-Roman religion and society which was very social-darwinist and autocratic. Christianity was hope for people oppressed socially or politically, but was eventually adopted by the upper classes because it was so popular further down and again served as a social tool to try to rally the Christian people to the Roman Empire in the late Roman days.
Islam: A tool to bring peace to the fractured and feuding tribes and city-states of Arabia. It applied the discipline and unity of Judaism and universalized it by removing the ethnocentric part of it and helped unite a fractured people to build a mighty civilization and empire based on a strong but fairly simple code of rules. Islam's interesting because it was the only one where faith and state were one in the same for quite some time, so it was popularized by law.
Shinto: This was part of the attempts of early Japan (around the era of Prince Shotoku and the time of Japanese unification) to legitimize themselves. The Kojiki and the Nihon Shoki were both written in roughly these time, and these were chronicles detailing the Japanese creation myth in a bid to prove that Japanese civilization was one that could stand proudly alongside China. As such, they ritualized native Japanese beliefs and turned a kind of animistic early religion into something that was codified and rule-based, similar to Taoism (so again, an attempt to imitate, although they also adopted Taoism and Confucianism and Buddhism and happily mingled them all. Japanese religion is weird).
So religion's purpose was not evil in its beginning, at least not any more than civilized society was evil. Some religions were born for temporal purposes, some for spiritual purposes, some basically just as cultural dick-wagging. As the religions institutionalized they became a part of the political fabric, and so could be used to help or to hurt over the years.
The correct question to ask about religion is that it's a tool that meets a need, whether good or bad, and the question to ask yourself when looking at a specific believer or a specific moment in religion is what need is this trying to meet, and can that need be fulfilled in a better way that doesn't have the bad side-effects that can come from a religion's baggage? If you look at Radical Islam, for instance, that's trying to meet a few needs in the Muslim World: rebellion for disaffected young men or politically disenfranchised rural tribes, a social tool against egregiously corrupt and materialistic ruling class, or a strike against Western cultural encroachment. It's a nexus of religion and politics to horrible effect, but understanding why can help address the issue and recommend cures like antipoverty initiatives, drives for political transparency and accountability, or less aggressive and exploitative foreign policies in Europe and North America.
Religion can complement political dogma, or be replaced by it. Doctrines like Bolshevism or Nazism or liberal Humanism try to replace religion in their own way by meeting a need, just de-mystifying the process. Religion should be viewed as a part of that spectrum.