A story of Yama's subordination to Shiva is well-illustrated in the case of Markandeya, where Shiva stops Yama and rescues his devotee Markandeya from his clutches.
The vedic 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. As per his destiny, the messengers of Yama came to take away Markandeya's soul, but failed to approach him as he ceaselessly repeated Shiva's name. Yama came himself to take Markandeya's soul and told Markandeya to stop his worship and come with him as per his fate. Markandeya refused, warning Yama that he was committing an offence against Shiva. Yama, however, proclaimed that not even Shiva could stop him. The wrathful Yama assumed a fearsome form and threw his noose to capture Markandeya, who embraced the linga. When the noose touched the linga, Shiva emerged from it and struck Yama with his Trishula and kicked his chest, killing the lord of death. Sages, gods and other beings appeared to praise Shiva, who blessed Markandeya to remain a youth of 16 for seven kalpas (aeons). As no one remained in the world to make beings die, the earth became burdened by evil beings. The earth, the gods, and Markandeya invoked Shiva to revive Yama. Once again, Shiva touched Yama with his foot, bringing him back to life. A sequel from Markandeya purana narrates how Shiva resurrected Yama on the request of the gods. Yama worships Shiva to atone for his sin