A man named Markandeya was an ardent devotee of Lord Shiva and worshipped Him day and night. As luck would have it, the span of life granted to him was a mere 16 years as stipulated in the book of destiny maintained by Yama.
After 16 years had passed, Yama sent his messengers to fetch Markandeya. On reaching the earth, they found that the victim lay clinging to a lingam and they dared not touch him as they did not want to invite Shiva’s wrath.
The messengers returned to Yama and told him about the incident. Yama personally decided to go and see Markandeya. He found the situation as described by his messengers. He tried to detach Markandeya from the lingam but failed. In a fit of anger, Yama tied a rope around Markandeya and the lingam and dragged them to hell.
Shiva, furious at the sight of his devotee being maltreated, kicked Yama to death, whereupon all earthly beings became immortal. After some time, this situation too became a problem as the world had no person left who would die. This led to an increase in the population and the earth plunged into misery.
All the gods got together to find a solution. It was decided to restore Yama back to life. So till today he continues to visit people to bring death upon them and thus the cycle of life and death continues.