A saint named Thavanithi was performing his worship in the temple. A deer chased by a hunter held the aegis of the saint.
The saint took the form of a tiger to frighten the hunter. The hunter out of fear climbed the Vilva tree in the temple, waiting for the tiger to relent
The tiger was relentless and the hunter in an effort to keep him awake all night spilled vilva leaves one by one the whole night. Incidentally the vilva leaves fell on a Shiva Lingam, under the tree.
Since the day was Maha Shivaratri, the hunter got the blessings of Shiva as a result. The next day was to be the last day of the hunter. Yama, the death god approached the hunter to take away his soul. Dakshinamurthy (Guru) with his trishula (trident) and Nandi were driving Yama out of the temple
.

Legend of the temple
Shiva was unhappy about Nandi and just to avoid Shiva's wrath Nandi faces the temple entrance.
It is also believed that Vishnu performed his penance here to overcome the curse of a chaste woman - the Shiva here is called Ariyeesar hence. Brahma and Agni held theertham here to worship Shiva here. The attributes of both Brahma and Agni was enhanced as a result. Saptamartrikas worshipped Shiva here by having a holy dip in Yama theertham, the temple tank here to regain the Ashtamasiddhi (powers) lost on account of a curse from the sage Uttala.
Shiva and Parvati appeared here in the northern banks of Cauvery and Bhuma Devi is believed to have worshiped Shiva and the place is called Bhooomipuram hence. Shiva rescued the life of a child who was killed by a thief for his jewels on a Shivaratri and attained the name Makavaruleeswarar.
During the great deluge, the land was supposed to be destroyed and the world worshipped Shiva, who rose in the form of Vilva tree to save the land. The presiding deity obtained the name Vilvavanehswarar hence. The temple is counted as one of the temples built on the northern banks of River Kaveri