Tolkien

Eucatastrophe

That’s the term JRR Tolkien invented to describe a terrible event that ends well. The climax of Lord of the Rings (when Sauron falls, not the scouring of the shire or all the loose ends) is a eucatastrophe. Luke Skywalker blowing up the Death Star is a eucatastrophe – because while the weapon of mass destruction was itself destroyed, nearly every pilot in his sortie was killed, and the rebellion had to retreat before imperial reinforcements arrived.