The temple was built during the Pallava regime in the 7th century. Kanchipuram was the capital of the Pallavas who ruled the region during the 6th to 9th centuries. They had Mamallapuram and Thiruvidanthai as their port towns and the two towns emerged as strong ports for the Empire. The temple is believed to have been built along with the monumental temples in the region. The temple has inscriptions dated 959 CE from the Pallava times. There were later additions from the Chola kings as indicated from an inscription during the 35th regnal year of Rajadhiraja Chola during 1052 CE. Raja Raja Chola is believed to have commissioned the Panguni Uthiram festival during 1003 CE. There are inscriptions indicating benevolent contributions from Kulothunga Chola I during 1115 CE. The temple is a declared monument of the Archaeological Survey of India on account of the inscriptions in the temple. It is maintained as a monument under the Chennai circle and Mamallapuram subcircle of the institution. The temple has a palanquin made of ivory, the one of its kind for any Hindu temple.
As per Hindu legend, Vishnu’s gatekeepers Jaya and Vijaya are cursed by sages that they would be born as asuras (demons) during their next birth. They were born on earth as Hiranyaksha and Hiranyakashipu to sage Kashyapa and his wife Diti. The demon brothers on account of their powers, take control of the universe. The elder brother Hiranyaksha practices penance and obtains a boon from Brahma which makes him invincible by any animal or human. Hiranyaksha captures earth, personified as goddess Bhudevi and hides her under the ocean All the celestial deities and sages went to Vishnu for rescue. Since Hiranyaksha did not include the boar in the list of animals that can slay him, Vishnu assumes this form with huge tusks and goes down to the primordial ocean. Hiranyaksha obstructs Varaha and the pair having a strong duel. Varaha lifts the earth on his tusks, which would go on to be the most common figurine representation of Varaha. The two fought each other with their mace, with Varaha emerging victorious after a thousand-year duel. Varaha emerges from the ocean with the earth in his tusks and repositions her in her original spot. The earth goddess Bhudevi falls in love with Varaha, whom he is believed to have taken in his lap in this place. It is also believed that a number of maidens awaited to marry the smart looking boar Varaha. It is believed that it is as per the wish of sage Kalava, who wanted Vishnu to marry his 360 daughters. Varaha married the 360 daughters one per day during the course of the whole year. Since he is believed to marry maidens daily, he came to be known as Nithyakalyana Perumal (meaning the Lord who marries daily).
As per another legend, a king by name Harikesarivarman used to visit the temple everyday from Mahabalipuram and wanted to settle at this place. Vishnu was pleased by his devotion and appeared as Sthalasayana Perumal at Mahabalipuram – the legend is associated with the Thirukadalmallai temple at Mahabalipuram.[