Set decades after the events of Ocarina of Time, the game begins with Link living in Ordon Village, working as a ranch hand. He is asked by Rusl, the village's blacksmith, to deliver the Ordon Sword to Hyrule Castle. Before he can begin his journey, Link, the mayor's daughter Ilia, and Rusl's son Colin are ambushed by a group of monsters. Ilia and Colin are kidnapped, and Link is knocked unconscious. Upon awakening, he pursues them, only to be pulled into the Twilight Realm, transformed into a wolf, and imprisoned in a castle. An imp-like creature named Midna helps him escape from his cell, and the two join forces.
Link and Midna travel through the castle until they meet another one of its prisoners - Princess Zelda herself. She explains that a member of a race known as the Twili is trying to merge the Twilight Realm and Hyrule to fuse them into one land of darkness. In order to defeat the king who rules over twilight, Midna is searching for a forbidden weapon called the Fused Shadow that she can use to defeat the evil king and save the Twilight Realm. However, Midna cares nothing for the fate of Hyrule.
During the quest to assemble this weapon, it is discovered that the Twili are a race of beings who were banished to the Twilight Realm by the gods of Hyrule. The Twili were interlopers with great magic who went to the holy Sacred Realm in order to establish dominion over it, causing a war to break out in Hyrule. After these sorcerers became too powerful, the goddesses sent three light spirits to seal away the beings' magic, and sealed the beings themselves away into another realm known as the Twilight Realm. The Twili who are left, are the descendants of the original beings who were banished. The goddesses created the Mirror of Twilight, a device to banish beings into the Twilight Realm (though it can also be used to enter the realm normally).
After many trials, Link and Midna re-assemble the Fused Shadow. However, the king of the twilight, Zant, appears, takes the Fused Shadows, and curses Link by embedding a stone into his forehead causing him to be trapped in his wolf form, and fatally injures Midna. Zant leaves, and Link rushes Midna back to Hyrule Castle to seek aid from Princess Zelda. At Hyrule Castle, Princess Zelda reveals that the only way Link can return back to his normal form is to find the Master Sword. Midna's life is fading away, and Zelda sacrifices herself to save Midna by turning herself into light and putting herself in Midna. This allows Midna to be her normal self in the world of light, not just a shadow. Midna and Link then venture deep into the Sacred Grove, and obtain the Master Sword. He also gains the ability to transform between wolf and human form through use of the stone that cursed him, and the Master Sword.
Mirror of Twilight
Midna explains that the only way to save Hyrule and stop Zant now is to find the Mirror of Twilight and use it to confront Zant with the Master Sword. However, when Link and Midna reach the Mirror, Zant had already broken it into four fragments. Only one fragment of the Mirror of Twilight is present. The ancient Sages who guard the Mirror appear, and reveal that an evil man named Ganondorf was sealed in the Twilight Realm after he was captured by the Sages. The Sages reveal that only the true ruler of the Twili could destroy the Mirror of Twilight, and that Zant could only fragment it.
With the help of a group of Hylians intent on establishing peace: Shad, Ashei, Auru, and Rusl, Ordon's blacksmith, Link ventures back in time to where the shards were sealed away. He goes to the Temple of Time, when it was still intact, the City in the Sky with the Sky Cannon, and the Snowpeak Ruins. With the Twilight Mirror restored, Link and Midna confront Zant in the Palace of Twilight in the Twilight Realm, and finally learn that Zant was actually in line to become the true Twilight King, but was passed over. When Zant was passed over, he went into a crazed rage, and was approached by the spirit of Ganondorf, who selected him to be a vessel for his power and help him regain his previous power (and unknown to Zant, be his puppet). It is revealed that Midna is the true Twilight Princess, and was overthrown by Zant and turned into an imp using Ganondorf's power.
Link defeats Zant, who claims that he will be revived as long as Ganondorf lives. Midna kills him using the regained Fused Shadows, which hold more power than she realized.
Zelda and Ganon
Link leaves and returns to Hyrule to save Zelda. The castle is engulfed by a barrier erected using Ganondorf's power, and Midna uses the Fused Shadow to break it. Link and Midna infiltrate Hyrule Castle and reach the top throne room to find Ganondorf sitting at the throne, and Zelda's lifeless body suspended above him. Ganondorf possesses Princess Zelda's body, and fights Link. Link wins the battle, and Midna then uses the Fused Shadow to purge Zelda of Ganondorf. He then turns into a beast-like form and attacks Link. Link defeats him, and Midna returns Zelda's soul to her body. Before the three of them can celebrate, Ganon's soul appears. Midna warps Link and Zelda to safety in Hyrule Field, and then tries to destroy Ganon using the Fused Shadow.
As Link and Zelda appear in Hyrule Field, they turn to Hyrule Castle and see a giant explosion emanating from it. They then see Ganondorf on horseback, holding Midna's helmet — he has defeated her. Princess Zelda uses her magic power to summon the Light Spirits. The spirits bestow upon her the Light Arrows, and then Link and Zelda re-appear in Hyrule Field on Epona and battle Ganondorf. Ganondorf falls from his horse in battle, but rises one last time to challenge Link to a one-on-one sword duel. In the end, Link defeats Ganondorf with the Master Sword. As Ganondorf stands impaled, the Triforce symbol fades from his hand. Zant is actually still alive and is seen briefly and snaps his neck, which appears to kill Ganondorf.
Now that the threat of Ganon has ended, Hyrule and the Twilight Realm are saved. Additionally, the curse that Zant put on Midna using Ganon's power has been lifted, and Midna regains her true form. After Link and Zelda are reunited with her, they travel to the Mirror of Twilight, to see Midna off before she returns home. Before Midna warps away, she shatters the Mirror of Twilight with a tear, sealing off the link between Hyrule and the Twilight Realm. Link is then seen riding towards his home town after staking the Master Sword in the Sacred Grove.