In the Mahabharata, many of the characters were a reincarnation of a God. Lord Vishnu decided to take birth as Lord Krishna and be a part of the action; following suit, several other Gods did too.
Dharmaraja Yama, God of Death and Justice, took birth as Lord Vidura, due to a curse that he got from the sage Mandavya. Vidura was considered to be an impartial man, with the ultimate knowledge of past, present and future. During his death, Vidura’s soul left his body and entered Yudhishthira