In reality, Agahnim was Gannon's alter ego. Agahnim took control of the castle very quickly. He murdered the king and isolated himself in the castle. This wasn't a problem because he also put the guards of the castle under a spell. Leaving him to do as he pleases.
Agahnim had an evil plan, to banish the decendents of the seven wise men into the Dark World to break the seal and unleash the evils there. Agahnim had banished six of the seven, the only one remaining being Princess Zelda. Zelda sent out a telepathic message to the decendent of the Hero of Time, Link.
The sixteen year old Link heard the plea in the middle of his sleep. When he awakened, he found his Uncle heading off, his uncle told him to stay there and that he'll be back in the morning. His uncle heard the plea as well.
Link soon headed off toward the castle to find out what was wrong. Not able to go through the front door Link searched for another entrance into the castle. Soon enough it was found, but to his dismay, he also found his uncle, wounded and unable to go on. Knowing the message was ment for Link and not him, his uncle gave him his sword and shield, explained how to use them, and passed on shortly after.
While searching the castle, Link found Zelda in the dungeon. Link beat all of the guards guarding her and released her. He took her to safety at a place she knew was connected to the castle, the sanctuary and was left in the care of a sage. Zelda told Link that she believed he was the hero that was going to save them from evil. The sage added in that the only way to stop Agahnim was with a sword that was created to reflect evil, the Master Sword. The same sword used to stop Ganondorf previously during the Imprisoning War.
Link discovered the only person who may be able to help him is the wise man of Kakariko Village. Link found that he was living in the desert and soon met up with him. He informed Link the only way to get the Master Sword was by getting three pendants. Each pendant was inside a differant part of Hyrule. The Eastern Palace, the Desert Palace, and the Tower of Hera were the locations of the pendants.
After defeating the masters in control of each of those locations he took the three pendants he earned to the Lost Woods where he retrieved the Master Sword. Soon after though he recieved a grim message from the Princess. She was captured by the evil Agahnim. Link went to save her, but when he found her Agahnim just broke the seal and sent Zelda into the Dark World. Link fought Aganhim and reflected his magic back at him, just before his defeat though, Agahnim banished Link into the Dark World.
Once there Link recieved a telepathic message from Sahasrahla. He explained that the only way to defeat Ganon and return peace was to save the seven decendents. Link soon set out to save them, he searched the Dark World far and wide. Once he had retrieved them all, the last being Princess Zelda, he went to Ganon's tower on the top of Death Mountain. There he met Agahinm for the second time, once beaten it is revealed that Agahnim is really Ganon's alter ego. Ganon changed himself into a bat, but Link persued to find a duel between the two.
Link using his Master Sword, silver arrows and of course courage defeated the evil Ganon. Inside this temple is where Ganon kept the Triforce also. Once defeated the Triforce was for the taking. Touching the Triforce and having a wish of goodness in his heart, all evil was removed from the Dark and Light Worlds and the Dark World was returned to its former state of being as the Sacred Realm. Upon returning the Triforce to Hyrule, he found the King of Hyrule and his Uncle had returned to life, and peace had returned to the kingdom.
And the Master Sword was once again laid to rest. . .