History in the Books
Rhaegal is first presented to Daenerys as a wedding gift from Khal Drogo alongside his brothers Viserion and Drogon as eggs. He later hatches when placed on the funeral pyre of Daenerys' husband, Khal Drogo (Drogon's namesake). When Daenerys tried to immolate herself with Khal Drogo, and sacrificed the witch who had left Khal Drogo in a permanent comatose state, the resulting sacrifice of life for life resulted in Rhaegal and his brothers hatching, with Daenerys being unharmed by the flames.
As Rhaegal grew, he was trained by Daenerys, who learned much of dragons by raising him and his brothers. During her time in the city of Qarth, the Sorcerers known as the Undying steal Rhaegal and Viserion, with Daenerys and Drogon coming to rescue them.
During her bargaining for soldiers in the city of Astapor, Daenerys uses Rhaegal's brother Drogon as payment for 8,000 Unsullied soldiers from the slavers known as the Good Masters. When she unleashes the Unsullied and has them kill the Masters, Rhaegal sows destruction upon them, burning them with his fiery breath. By this time, he is as large as a dog.
During her time in Mereen, Rhaegal and his siblings begin to misbehave. When Drogon is blamed for supposedly killing and eating a little girl, with her blackened bones being presented by the child's father as evidence to Daenerys, Rhaegal and Viserion are chained up in a makeshift dragon-pit as a precaution. When the lord Quentyn Martell tries to tame the dragons, Rhaegal fatally burns him with dragonfire. Once he has escaped from the pit, Rhaegal makes his new lair in the great black pyramid of Yherizan, where he hulks in the gloom like a fat woman bedecked with glowing orange jewels. The pyramid is now a smoldering ruin, and its former occupants are either dead or have fled the dragon's wrath. His fate afterward is unknown.
History in the TV Series
Rhaegal's history is much the same in the television series as in the books, but he is shown to be far more loyal to Daenerys than in the books, and has grown faster and larger than in the books, though not as big as Drogon.
Rhaegal is again presented as an egg by Khal Drogo as his wedding present to Daenerys alongside Drogon and Viserion's eggs. However, Viserys Targaryen, Daenerys' older, mentally unstable brother, tried stealing the eggs, only to be stopped by Ser Jorah Mormont. He hatches in the same way as in the books, placed on the funeral pyre of the dead Khal Drogo, with Daenerys walking into the flames to immolate herself, causing him and his brothers to hatch.
During their time in Qarth, it is Pyat Pree that steals the dragons and places them in the House of the Undying, taking all three instead of just Rhaegal and Viserion as seen in the novels, before luring Daenerys to them to keep his magic strong, as his magic is empowered by the dragons' magic and that they are strongest in her presence. When she is chained up with her dragons, Daenerys unconcernedly whispers "Dracarys", signaling her dragons to breathe fire, and they burn Pyat Pree to death before incinerating the House of the Undying.
Rhaegal, along with his brothers, accompanies Daenerys on her journey from Astapor and Yunkai. When Daenerys has a meeting with a Razdal mo Eraz, of the Wise Masters of Yunkai, Rhaegal hisses at the slaver along with his brother Drogon when he comes too close to Daenerys. He then fights over a piece of meat with his brothers when Daenerys makes a show of force to intimidate Razdal. After Daenerys frees the slaves of Yunkai, Rhaegal takes to the sky with his siblings at Daenerys's command; a show of both power and freedom to the newly liberated people.
Rhaegal is seen with his brother Viserion fighting over a dead sheep they have killed. Drogon, who is now visibly bigger than them, quickly takes the lamb as his brothers squeal for him to share. He sets the corpse down and the three begin to eat. In response to Drogon's killing of a three-year-old girl, Daenerys leads Viserion and Rhaegal into the catacombs of Meereen, where she chains them up, much to her pain.
After some time, Daenerys finally decides to reenter the catacombs to attempt to regain control over her dragons. Rhaegal and Viserion, who have grown even larger during their time in captivity, now around as large as orcas, immediately lash out and breathe fire in anger at the sight of their mother who imprisoned them. Later, Daenerys, reeling over the death of Ser Barristan Selmy, the leader of her Queensguard, arrests the leaders of Meereen's great families and brings them to meet Rhaegal and Viserion. Rhaegal roasts one of nobles and begins to eat, sharing the meal with Viserion. Her point proven, Daenerys leaves, sarcastically saying that she doesn't want to overfeed the dragons.
In the Great Pyramid, Tyrion Lannister learns that Rhaegal and Viserion have not been eating anything ever since their mother had left. He then decides to free them, knowing that they will be better off that way and knowing they may die otherwise. Accompanied to the entranceway by Varys, Tyrion ventures alone into the catacombs and encounters Rhaegal and Viserion for the first time. By this time, they are now around 60 feet long and are evermore fearsome in appearance. Despite their initial hostility towards him, Tyrion remains calm, assuring them he is a friend of Daenerys and only wants to help them. He manages to earn their trust and unshackle them while telling them the story of how he wanted a dragon for his nameday, only to be disappointed by uproarious laughter from his family and the cold truth from his father. Once free, the dragons immediately depart into the darkness of the catacombs while Tyrion quickly exits with Varys, asking the latter to punch him in the face the next time he decided to try something that stupid again.
After Daenerys returns to Meereen and pits Drogon against the fleet assembled by Astapor, Yunkai, and Volantis, Rhaegal and Viserion break out of the catacombs and join their mother and brother in destroying the the slavers' fleet with dragon fire, decisively breaking the Second Siege of Meereen. This defeat marks the end attempt to reintroduce slavery to Meereen and allows Daenerys to take the enemy fleet for her own.
Some time later, Rhaegal and his brothers accompany their mother and her large army on a voyage to retake Westeros by soaring above the armada.