Originally, the venue of the fair was Hajipur and only the performance of the puja used to take place at the Harihar Nath temple of Sonepur. However, under the rule of the Mughal Emperor Aurangzeb, the venue of the fair got shifted to Sonepur. The temple of Harihar Nath is believed to have been originally built by Lord Rama, on his way to the court of King Janak to win the hand of Mata Sita. It is further said that Raja Man Singh later got the temple repaired. The Harihar Nath temple, as it stands today, was built by Raja Ram Narain, an influential person during the late Mughal period.
Gajendhra Moksha legend is associated with the temple in Sonepur. It involves the story of king Indrayamuna and the Gandharva chief Huhu, who were turned into an elephant and a crocodile respectively by the curse of great sages Agasthya and Dewala muni. One day the elephant's leg was caught by the crocodile.It is said that the location was in Nepal. It is said that both of them fought hard for many years with their herds and while fighting, they came to the place near this temple. But ultimately the King Elephant weakened and took the lotus flower from river in its trunk and prayed to the supreme god Vishnu (Hari) to save him. Vishnu heard his prayer and cut down the crocodile with his Chakra. But the touch of the chakra released Huhu from the curse. Vishnu also released Indrayamuna from his curse and took him to his abode Vaikuntha.
Since Sonepur is situated at the convergence of the sacred rivers Ganges and Gandak, the Hindus regard it as a holy site. One of the purposes of the people visiting the Sonepur Cattle Fair, apart from the fair, is to take a holy dip at the convergence and pay respects at the Hariharnath Temple.