After Link pulled out the Master Sword he was teleported to the Temple of Light for seven years. This happened because he was so young. When he pulled out the sword he was not old enough to be the Hero of Time yet. There Rauru explains what happens in that seven years and what he must do to stop Ganondorf now that he has the Triforce.
After Link was taken seven years in the future Ganondorf had easy access to the sacred realm because the seal was already broken. When he got there the Triforce shone from its resting place high above the world. When Ganondorf grasped it he heard a whispered voice "If thou has a strong desire or dream, wish for it . . ."
Because the Triforce is an inanimate object it cannot judge between good and evil. It did not know Ganondorf's wishes were evil it merely granted them. Ganandorf wished to conquer the world. After this was wished, the sacred realm became the dark world and greedy men were drawn in to become members of Ganondorf's army. Black clouds permanently darkened the sky, and many disasters came to Hyrule.
Rauru told Link what he must do to stop Ganondorf was to awaken the 7 sages and seal Ganondorf into the sacred realm. The Lord of Hyrule ordered earlier to seal the sacred realm, but it failed. Rauru explained that he was the sage of light, but Link had to find five others and a seventh one to bring them all together. The five sages he had to find were Saria, the sage of the forest, Darunia, the sage of fire, Ruto, the sage of water, Impa the sage of shadow and Nabooru, the sage of the desert. The seventh sage, the leader of them all was Princess Zelda.
Princess Zelda has been halping Link out in secret. She took the identity of a boy named Sheik. She watched Link's progress until the time was right, when he awakened the other six sages. When she revealed herself to him she explained more of what happened on that day seven years ago.
A legend says that when someone with a pure heart touches the Triforce, the Triforce stays intact. But when someone with an evil heart touches it the Triforce splits and the part that stays with the person is the part that most represents him and the others hide. The only way for the Triforce to stay whole, is to get the other two pieces again. The legend became true when Ganondorf touched it. The Triforce of Power stayed with him, while the Triforce of Wisdom went to Zelda and the Triforce of Courage went to Link.
When Zelda revealed herself it made it possible for Ganondorf to find her. Ganondorf now knowing where the other two parts are kidnapped the Princess to his castle. Link quickly followed after. Link courageously fought his way through the castle. Once he broke the barrier protecting Ganondorf's tower Link headed straight up to the top. Ganondorf was waiting for him though, so the Triforce would merge back into one. The battle was fierce, but Link, the Hero of Time, prevailed.
Zelda was freed, but now was not the time to become overjoyed, Ganondorf was trying with the last of his power to destroy the tower. As the tower started to fall, Zelda used her wisdom to get Link and her both out saftly. On the ruins of the castle Ganondorf used his piece of the Triforce to become Ganon, and try to stop Link one more time. Ganon's new form may have been difficult to fight but it was no help to his evil cause, Link beat him again. This fighting gave the Sages time to seal Ganon into the dark realm.
All of the Knights of Hyrule sent out by the lord perished, but Link for defeating Ganondorf was named a Knight of Hyrule. Ganondorf swore revenge on the decendents of the sages, Zelda and Link.
Peace soon returned to Hyrule and the races began to rejoice. Zelda realizes that Link needed to regain the seven years of life he lost and so she sends him back in time to live his time as the boy in the forest.
This battle between good and evil is later known as the Imprisoning War in stories told.