Itachi disappears. Sasuke sees him off.
The Edo Tensei shinobi disappear one after the other
Dan is able to move his body of his own will now, so he dissipates Chouza's barrier and uses his Reika no Jutsu to go to Tsunade.
Madara attacks the Kage before disappearing. Tsunade takes damage and her Byakugou no Jutsu wears off.
At the same time, Madara's soul leaves his body so Tsunade believes they won, but Madara's soul returns to his body and he attacks with Susano-o.
Dan arrives in time to control Tsunade and saves her in the nick of time. The two are reunited. Dan kisses her on the forehead and says "I was able to save you in the end... I guess being brought back by Edo Tensei isn't all bad..." and disappears.
Tsunade gets some chakra from him(not sure about this) and her vitality is restored.
Madara's soul returns because as long as he knows the seals for Edo Tensei, the dead person who was revived can cancel the contract.
In other words, he can move in in undying body with infinite chakra with no restraints.