As the conflict intensified into full scale war, Aegon II grew increasingly impatient with his grandfather Otto Hightower's diplomatic maneuverings, and wanted to launch an immediate attack on Rhaenyra's followers on the mainland. With Lord Commander Criston Cole, he launched a campaign into the east of the Crownlands held by the Blacks.
This culminated in the Battle of Rook's Rest, when Rhaenys Velaryon arrived riding the large older dragon Meleys to attempt to lift the siege of the castle. This was all a trap, however, as the Greens had kept two of their own dragons hidden and in reserve so they could take Meleys in an uneven fight. Aegon II appeared riding the younger but strong Sunfyre, and his younger brother Aemond Targaryen also attacked riding the massive Vhagar, last of the first generation Targaryen dragons.
Rhaenys could not prevail against such odds, yet she did not flee but flew head-on to meet her attackers. Meleys was still so large and powerful that she put up a brutal fight. When the dust settled Meleys was dead and Vhagar was relatively unharmed, but Sunfyre had been nearly killed and permanently maimed. Meleys managed to nearly rip one of his wing-arms completely from his body, and as for Aegon II, he was left horrifically burned and with multiple broken bones. Aegon II was taken back to King's Landing, but he was left sedated with Milk of the Poppy for months, and command fell to his yougner brother Aemond.
Sunfyre survived the battle but the world's most beautiful living dragon was left crippled and heavily scarred.
Yet even after Rhaenyra captured King's Landing, her forces could not find Sunfyre. A year after Rook's Rest, Aegon II suddeny seized Rhaenyra's home base at Dragonstone, with the wounded and dying Sunfyre by his side. When Rhaenyra was forced to flee King's Landing due to a city-wide riot, she returned to Dragonstone only to be confronted by her half-brother. Aegon II then had Rhaenyra fed to his dragon Sunfyre while forcing her last remaining son to watch (Aegon III Targaryen). The dragon roasted her alive and devoured her in six bites - the seventh bite he left (said to be The Stranger's bite), leaving one of her feet as the only part he didn't consume.
In the books
Sunfyre was a relatively young dragon given that Aegon II appears to have been his first and only rider. He was not considered one of the "large" dragons like Caraxes or Syrax. At the same time he was very much at the upper end of the "medium" dragons, very strong and formidable in combat.
The Season 5 Blu-ray featurette about the Dance of the Dragons condenses the story significantly and thus doesn't really explain what happened to Sunfyre between Rook's Rest and when he later showed up on Dragonstone a full year later, only to say that the dragon was dying.
In short, Sunfyre couldn't fly for months due to his crippled wing, and even then the bones healed at a bad angle. He eventually regained the ability to fly again, albeit awkwardly - enough to travel from place to place but not enough to maneuver well against other dragons in the air.
Aegon II escaped King's Landing to hide out as a disguised commoner in a fishing village on Dragonstone island - the last place that Rhaenyra would look. For some reason, and the historians still debate this, Sunfyre also subsequently flew to Dragonstone after he gained enough strength to fly. Some think it was simply a nesting instinct, given that all the dragons were hatched on the Dragonmont volcano and it thought it would be safe there. Others who think dragons are more intelligent or have some sort of magical pyschic bond with their riders think that Sunfyre sensed where Aegon II was. Whatever the case, when Sunfyre arrived he fought and killed a remaining riderless dragon, Grey Ghost - though he took yet more wounds in the process.
It wasn't long before Aegon II and Sunfyre found each other again, and both crippled beings found new purpose in each other. Aegon II then recruited traitors among the skeleton garrison that Rhaenyra had left on Dragonstone with promises of reward, and moved to take the castle. Not all went as he had planned, however, for as he flew Sunfyre into the courtyard to stake his claim, he was attacked by Daemon's young daughter Baela riding the dragon Moondancer - an even younger dragon barely large enough to carry the 13 year old girl. Moondancer was quick and nimble, however, while Sunfyre was still half-crippled and slowed by his injuries. They were therefore evenly matched and their duel was ferocious. It culminated when Sunfyre tackled Moondancer in mid-air and drove her into the ground below: his larger size meant that he survived the fall while she was killed. Nonetheless Sunfyre was mortally injured by this fight, and would never fly again.
When Rhaenyra arrived back on Dragonstone and encountered Sunfyre, the once most beautiful dragon in the world had been reduced to a horrifying spectacle: open wounds along his neck, back and belly, bent broken wings that would never fly again, and even missing one of his eyes. Sunfyre never recovered from his injuries: Aegon II's men attempted to nurse him back to health by bringing him sheep to eat, but eventually he succumbed to his massive internal injuries only six agony-filled weeks after he ate Rhaenyra. Aegon II wept at his passing.
Despite being one of the younger dragons in the Dance, Sunfyre actually shared the highest dragon versus dragon kill count with the massive Vhagar herself: two individual kills and one assisted (when Sunfyre and Vhagar doubled up on Meleys at Rook's Rest). Both Sunfyre and Vhagar died as a result of their third dragon fights (Vhagar immediately, Sunfyre mortally wounded). For that matter, they were the only two dragons in the Dance who ever lived through a dragon versus dragon fight and lived (most dragons in the war were actually killed by human armies, or died in mutual kills in their first battle against another dragon).
Meleys · Meraxes · Morghul · Seasmoke · Sheepstealer · Shrykos · Silverwing · Sunfyre
Stormcloud · Syrax · Tyraxes · Valryon · Vermax · Vermithor · Vermithrax · Vhagar