As per Hindu legend, the temple is associated with the times of Ramayana. Raghunathji (Rama, an avatar of Vishnu) is believed to performed penance at this place to relieve himself off the curse committed by killing Ravana, a Brahmin demon king. While Rama was offering his prayers in the waters of Devaprayag, Pushpamala came to Rama for rescue. Rama killed the Makara that was troubling her with his sword.
Soon after killing, the sword went to heaven.Brahma, the Hindu god of creation, is once believed to have performed penance at this place and the place came to be known as Prayaga, meaning the best place to do penance. As per the same legend, the Vataka tree (Banyan tree) in the place would withstand all earthly disasters and would remain through ages. Vishnu is believed to reside in the leaves of the tree. The Pandavas performed penance at this place before the Mahabharat war. Sage Bharadwaja is also believed to have performed penance at this place and became of the seven sacred sages, the Saptarishis.
The temple is originally in existence from the 9th to 10th century. The temple was originally believed to have been established by Adi Shankara during the 8th century, with later expansions by the Garhwal Kingdom. Garhwal (also the ruling dynasty), the region in Himalayas, where the temple is located, is referred with the name for the first time in a copper plate inscription in the temple from the period of Raja Man Shah during 1610.
The temple received contributions from other rulers of the dynasty like Sahaj Pal, who donated a bell to the temple in 1551, as indicated by the inscriptions in the temple. Man Shah, the other ruler of the dynasty made contributions and is indicted in the inscriptions from 1610 CE.
The region was ruled by Raja Prithvi Pat Shah as seen from the inscriptions in the door and doorways in the temple dated to 1664. King Jai Kirthi Shah who ruled the region during 1780, ended his life in the temple as he was betrayed by his courtsmen.It was damaged during an earthquake during 1893 and was built by the local king subsequently. In modern times, the temple is maintained and administered by the Uttarakhand Tourism Development Board of the Government of Uttarakhand.