The White Wizard
Gandalf was sent back as a significantly more powerful figure, Gandalf the White. Gwaihir carried him to Lórien, where he was healed of his injuries and re-clothed in white robes by Galadriel. He travelled to Fangorn Forest, where he encountered Aragorn, Gimli, and Legolas (who were tracking Merry and Pippin).
They travelled to Rohan, where Gandalf found that Théoden had been further weakened by Wormtongue's influence. He broke Wormtongue's hold over Théoden, and convinced the king to join in the fight against Sauron. Gandalf then set off to gather Erkenbrand of the Westfold and his warriors to assist Théoden in the coming battle with Saruman. Gandalf arrived just in time to shatter Saruman's attack on Helm's Deep. After the ensuing battle, Gandalf and the king rode to Isengard, which in the interim had itself been attacked and conquered by Treebeard and the Ents, along with Merry and Pippin. Gandalf broke Saruman's staff and expelled him from the White Council and the Order of Wizards, and assumed Saruman's place as head of both. Wormtongue made an indecisive attempt to kill Gandalf or Saruman with the palantír of Orthanc, but missed both. Pippin retrieved the palantír, but Gandalf quickly appropriated it. After the group left Isengard, Pippin took the palantír from a sleeping Gandalf, looked into it, and came face to face with Sauron himself. Gandalf then took the chastened Pippin with him to Minas Tirith to keep the young Hobbit out of further trouble.
Gandalf arrived in time to help order the defences of Minas Tirith. His presence was resented by Denethor, the Steward of Gondor; but after Denethor's son Faramir was gravely wounded in battle, Denethor sank into despair and madness. Together with Prince Imrahil of Dol Amroth, Gandalf led the defenders during the siege of the city. When the forces of Mordor finally broke the main gate, Gandalf alone on Shadowfax confronted the Witch-king of Angmar, Lord of the Nazgûl. But at that moment the Rohirrim arrived, compelling the Witch-king to withdraw and engage them. Gandalf would have ridden to their aid, but he too was suddenly required elsewhere — to save Faramir from Denethor, who sought in desperation to burn himself and his son on a funeral pyre.Aragorn and Gandalf then led the final campaign against Sauron's forces at the Black Gate, in an effort to distract the Dark Lord's attention from Frodo and Samwise Gamgee, who were at the same moment scaling Mount Doom to destroy the Ring. In a parlay before the battle, Gandalf and the other leaders of the West met the Mouth of Sauron, who showed them Frodo's mithril shirt and other items from the Hobbits' equipment. But Gandalf rejected Mordor's terms of surrender, and the forces of the West faced the full might of Sauron's armies, until the Ring was destroyed in Orodruin. Gandalf led the Eagles to rescue Frodo and Sam from the erupting Orodruin.
After the war, Gandalf crowned Aragorn as King Elessar, and helped him find a sapling of the White Tree of Gondor. He accompanied the Hobbits back to the borders of the Shire, before leaving to visit Tom Bombadil. Two years later, Gandalf — who by now had spent about 2,000 years in Middle-earth — departed with Frodo, Bilbo, Galadriel, and Elrond across the sea to the Undying Lands. It was only then that his possession of Narya, one of the Three Elven Rings, became generally known