One legend relates the story of how Shiva protected Markandeya from the clutches of death, personified as Yama.
Mrikandu rishi and his wife Marudmati worshipped Shiva and sought from him the boon of begetting a son. As a result, he was given the choice of either a gifted son, but with a short life on earth or a child of low intelligence but with a long life. Mrikandu rishi chose the former, and was blessed with Markandeya, an exemplary son, destined to die at the age of 16.
Markandeya grew up to be a great devotee of Shiva and on the day of his destined death he continued his worship of Shiva in his aniconic form of Shivalingam. The messengers of Yama, the god of death were unable to take away his life because of his great devotion and continual worship of Shiva. Yama then came in person to take away Markandeya's life, and sprung his noose around the young sage's neck. By accident or fate the noose mistakenly landed around the Shivalingam, and out of it, Shiva emerged in all his fury attacking Yama for his act of aggression.
After defeating Yama in battle to the point of death, Shiva then revived him, under the condition that the devout youth would live forever.
For this act, Shiva was thereafter known also as Kalantaka ("Ender of Death"). This is believed to have happened in Thirukkadaiyur, Tamil Nadu.
As sourced from Sati Purana, a secret portion of Markandeya Purana, Goddess Parvati also gave him a boon to write a text on veer charitra (Fighting character) on her, the text is famously known as Durga Saptashati, a valuable portion in Markandeya Purana. The place is known as Yamkeshwar.