To understand Ganondorf, one would have to search back to the first era, before Hyrule's creation. For the Demon King Demise unleashed an unspeakable evil upon the world. However, he was thwarted by a hero in green, Link, and his princess, Zelda. But before he would perish, Demise set fourth a terrible curse. That one day, his evil would return and manifest itself into a person, thus this man would take on the mantle of Demise. That being, Ganondorf Dragmire of Gerudo. But in doing so, Link and Zelda would also be reincarnated time and again.
In the beginning, Ganondorf started small and played the King of Hyrule as a potential ally, swearing fealty and tribute in order to get close. And while the King was fooled by his charm, the princess, though a child at the time, was not. She eventually began a secret mission to grab sacred relics needed to open the temple of time with the help of the reincarnated hero, Link. But in doing so, sealed the hero in a seven year stasis.
This was all Ganondorf needed to take what he had desired since the beginning. For the Temple of Time npt only held the powerful master sword- the very weapon used to defeat Demise, but also an Ancient relic known as the triforce. A promise from the three goddesses after they left the world. For whoever wields the three pieces would determine the fate of the world. Those with a pure heart would ensure peace and prosperity in an unrivaled age, while those with a heart of evil would thus doom the world to oblivion.
Ganondorf with his evil corruption, managed to steal the triforce, which bolstered his armies. The land of Hyrule soon fell as they were unable to match the might of his minions. That is until Link, now freed from his seal, was able to wield the master sword. But Ganondorf was more than prepared for the inevitable return of his nemesis. As time drew near, Ganondorf began to capture and seal and/or kill those who would protect the land of Hyrule~ sacred guardians known as the six sages. In order to get to the Gerudo King, Link would have to locate and rescue the six sages. But once more, the king laid a trap. As one of Link's assistants revealed herself to be a much older Zelda, Ganondorf ambushed the duo and kidnapped her, as she held a piece of the triforce. This prompted Link to give chase until he was able to reach his way to his newly acquired castle for one final epic battle.
Though as Ganondorf was loosing the fight, he decided to crash the entire superstructure of the building around Link and Zelda. The two daringly rushed through the building, and narrowly escaped. But so did Ganondorf. Even as he was mortally wounded, the king still held the Triforce of Power, and used it to unleash every ounce of magical ability he had in him to transform him into Beast Ganon~ A feral, yet godly powerful entity, whom was only sealed and defeated thanks to Zelda, Link and the Master Sword.
In a separate time, Link returns to the princess when they were children to warn her of Ganondorf's plot with supporting evidence. This is brought before the King Of Hyrule and as a result, the Guardian sages sentenced the king to death. However his execution was botched, and he was sealed. But like before his seal was broken, and Ganondorf was able to return with a new army from another realm~ this time through the realm of Twilight. Again, with the help of Link's descendant, again named Link, as he took up the hero mantle, was able to slay Ganondorf and restore peace to the realm of Hyule.