Some time during the Merethic Era, Durnehviir was captured by the Ideal Masters of the Soul Cairn after his soul was captured for unknown reasons. He was tasked to guard the Soul Cairn during that time, destroying any potential hazards/souls that developed within the realm.
Eventually when Lord Harkon learned about a prophecy where vampires did not have to fear the dark anymore and that his daughter Serana was part of the prophecy, his wife Valerica hid Serana within Deephollow Crypt and sought refuge in the Soul Cairn to prevent Lord Harkon from ever finding them. The Ideal Masters caught on to this action, and tasked Durnehviir to guard her and prevent her from escaping as part of a deal she made with the masters.
When the Dragonborn and Serana arrive in the Soul Cairn, they are told by Valerica to defeat three Soul Masters that have a barrier up in the fortress she sought refuge inside. Afterwards, Durnehviir will be alerted by the Ideal Masters and order to attack Valerica, Serana, and the Dragonborn. The Dragonborn successfully "slays" him, but fails to absorb his soul, but shrugs it off and obtains the Elder Scroll from Valerica.
When leaving the fortress, the Dargonborn will encounter Durnehviir well-alive. When asked why he is alive despite the fact that the Dragonborn "killed" him. He will reveal that he was only defeated, as his soul was already captured in the soul cairn and that he is already "dead", stating that his soul will only be separated and then rematerialized some time afterwards. He then offers a request for the Dragonborn, to set him free from the soul cairn, and in exchange, will fight alongside him in battles temporarily (in a similar way as Odahviing), as well as teaching him/her a word for the Soul Tear shout. He will advise the Dragonborn that they must do this three times before he is completely freed from the soul cairn. When and if the Dragonborn agrees, he will grant them the necessary words to summon him, thus officially befriending him.
Anytime while the Dragonborn is out in the Skyrim wilderness, they can use the shout to summon Durnehviir, however it order for it to succeed, he/she must use all three words and being located in an open area. Once summoned, Durnehviir will provide the Dragonborn with a word of the Soul Tear shout before taking off in flight, assisting the Dragonborn in battle for a short time before being sent back to the soul cairn.
After the Dragonborn summons him for the third, he will reveal that he is fully released from the soul cairn. And that if the dragonborn can use his summoning shout anytime they need his help in the future.