The origin of the Hero of Time is not known officially. We know from the game that Link's mother was fleeing from a war taking place in Hyrule, and brought her son to the Kokiri Forest to be raised in peace. According to the Deku Tree Sprout, "Some time ago, before the King of Hyrule unified this country, there was a fierce war in our world. One day, to escape from the fires of the war, a Hylian mother and her baby boy entered this forbidden forest."
Other clues can be found in other games. For example, according to A Link to the Past, legendary Heroes must come from the line of knights of Hyrule, bringing most people to assume that Link's father was a knight who was probably killed during the war.
Role in Hyrule's History
The Hero of Time in Ocarina of Time
In Ocarina of Time, a young Link has been raised as one of the Kokiri, the “children of the forest” (who are thought to have later become the Koroks in Wind Waker). Always considered an outsider by Mido, the leader of the Kokiri (due to the fact that, unlike other Kokiri, Link did not have a fairy companion) Link became very good friends with Saria, the object of Mido’s affection. Link’s life changes one day when the Great Deku Tree sends a fairy, Navi, with instructions to bring Link immediately.
After bypassing a distraught Mido, Link battles a curse put on the Tree by Ganondorf, an evil Gerudo thief from the desert. Although he is successful in breaking the curse, he is too late. Dying, the Deku Tree directs Link to Hyrule Castle, where he encounters Princess Zelda. She sends him on a mission to collect three Spiritual Stones and save Hyrule. Once Link obtains the stones, he travels to the Temple of Time and opens the Door of Time with the Stones and the Ocarina of Time. He then draws the Master Sword from its stone pedestal. This action imprisons Link in the Temple of Light for seven years, while Ganondorf takes control of Hyrule and seizes the Triforce, a legendary artifact hidden in the Sacred Realm by the three goddesses, holding unimaginable magical power.
Seven years after drawing the sword from the pedestal, Link is awakened as the Hero of Time by Rauru, Sage of Light. Link finds that much time has passed, and he has grown up. He sets off on a quest to cleanse the land of Ganondorf’s evil. Returning to the Kokiri Forest, he finds that none of his friends have grown up, and most now don’t recognize him! Finally he meets the Deku Sprout (the Great Deku Tree’s successor), who reveals the hidden story of his past.
The reason Link has grown, while his Kokiri friends have not, is that he is actually a Hylian, orphaned in the Hyrulean Wars. When Link was a baby, his mother fled with him to Kokiri Forest, and, mortally wounded, left him under the Deku Tree’s protection. He was brought up as one of the Kokiri, and knew no differently. Now, Link must rescue the other five sages from their temples so they can awaken to their powers and lock Ganondorf away in the Sacred Realm. After Link gathers the sages in the Temple of Light, the final Sage, Zelda, reveals herself and is captured by Ganondorf—who could only hold on to the Triforce of Power, and now seeks to recover Wisdom and Courage by sacrificing Link and Zelda. Fighting through Ganondorf’s castle, Link confronts and seemingly defeats the tyrant. But the King of Evil reveals the true blackness in his heart, and, using the Triforce of Power, transforms into the monstrous Ganon. After Link triumphs over Ganon, Princess Zelda uses the power of the Ocarina of Time to return Link to the past and allow him to live out the seven years of his youth taken from him while he was sealed away by the Master Sword.
At this point, the Zelda series has its infamous timeline split. Because Ocarina of Time dealt with time travel, there are two endings or "timelines", two ways in which Hyrule's story then diverges. The first is the Hyrule that was freed from Ganon by teenage Link, which no longer has a hero once he disappears back to his childhood time. In that timeline, the Hero of Time has no other role.
But in the timeline where Link returns to the Hyrule of his childhood, Ganon never enters the Sacred Realm, and it is as if nothing has happened at all. From there on, the Hero of Time has several other adventures, none of which are in Hyrule.
The Hero of Time in Majora's Mask
The introduction to Majora's Mask explains that, after he saves Hyrule, young Link sets off on Epona supposedly in search of Navi, who left him at the end of Ocarina of Time. As he travels through some unidentifiable woods, Skull Kid, wearing a strange mask, ambushes him and steals the Ocarina of Time. After Link chases him into the land of Termina, Skull Kid casts a curse on him that turns him into a Deku Scrub. One of Skull Kid's faries, Tatl, gets left behind and eventually joins Link. Her brother, Tael, stays with Skull Kid.
Desperate, Link continues on until he finds himself in Clock Town, where he meets the Happy Mask Salesman. He explains to Link that Skull Kid stole the Majora's Mask from him, and that he needs it back in three days. This is sort of convenient too, because it turns out Termina's moon is about to ram into Clock Town and kill everyone in about three days, so it all works out. If Link can, at the very least, get back the ocarina, then he could turn him back to his normal form.
After three days Link climbs to the top of the clock tower and retrieves the Ocarina of Time from Skull Kid. After a flashback to Zelda talking about the Song of Time (Zelda's only appearance in Majora's Mask), Link is transported back in time to the morning three days earlier, when he arrived in Termina. The Happy Mask Salesman teaches Link the Song of Healing, which turns the Deku Scrub curse placed on him into a mask. Wearing this mask makes Link turn back into a Deku Scrub.
From there, Link travels to the four corners of Termina to retrieve four cursed masks worn by each dungeon's boss, freeing one of Termina's giant gods each time. Along the way, Link acquires two other masks, the Zora Mask and Goron Mask, which let him turn into a Zora or Goron, respectfully, along with a plethora of other masks. After freeing all four giants over numerous backtracks through time, Link returns to the top of the clock tower to face Skull Kid and Majora, who is controlling him through the mask. He summons the four giants to hold the moon up and keep it from crashing as he battles the mask inside of it.
Upon entering the moon, Link finds himself in a bizarrely beautiful open field, complete with flowers and a crystal sky. Far away, a huge tree sits at the top of a small hill. When he approaches it, he finds five children, with four wearing the boss masks and the last wearing Majora's mask. After playing with the others, the Majora kid invites him to play. At this point, if the player has collected and given up all of the attainable masks in the game, the Majora kid gives Link the Fierce Deity Mask, which turns Link into Oni Link.
After defeating Majora, the sun is finally able to rise on the "fourth day", and Termina survives.