As the agents of Yama, the god of the netherworld, their role is to take the departed souls of the deceased who do not achieve moksha to Yamaloka.
Ajamila is a Brahmin who once set out to the jungle to collect fruits, flowers, sticks for sacrificial fire, and kusha grass.
When he was on his deathbed, when the messengers of Yama were waiting to take him to hell, he called out the name of his favourite son, Narayana, which was also an epithet of Vishnu.
The matter in dispute, the Yamadutas brought the Brahmin to an audience with Yama, and the Vishnudutas explained that the Shastras (religious scriptures) state that the mere utterance or the recitation of the name of Vishnu, even if taken to denote another person, or in a friendly joke, or as an insertion during the recitation of a song, or even as an apparent insult, completely annihilates all the sins of the one who utters it., and the deity of death affirmed that the Vishnudutas were on the right, upon which the messengers of death extoled the glories of Vishnu.
[2] This legend is the origin of the belief that the Yamadutas steer clear of Vaishnavas, or in the very least carry them to Vaikuntha rather than Yamaloka.