A happy ending is an ending of the plot of a work of fiction in which almost everything turns out for the best for the main protagonists, their sidekicks, and the main villains/antagonists are defeated.
In storylines where the protagonists are in physical danger, a happy ending mainly consists of their survival and successful completion of the quest or mission; where there is no physical danger, a happy ending may be lovers consummating their love despite various factors which may have thwarted it. A considerable number of storylines combine both situations. In Steven Spielberg's version of "War of the Worlds", the happy ending consists of three distinct elements: The protagonists all survive the countless perils of their journey; humanity as a whole survives the alien invasion; and the protagonist father regains the respect of his estranged children. The plot is so constructed that all three are needed for the audience's feeling of satisfaction in the end.
A happy ending is epitomized in the standard fairy tale ending phrase, "happily ever after" or "and they lived happily ever after". (One Thousand and One Nights has the more restrained formula "they lived happily until there came to them the One who Destroys all Happiness" (i.e. Death); likewise, the Russian versions of fairy tales typically end with "they lived long and happily, and died together on the same day".) Satisfactory happy endings are happy for the reader as well, in that the characters they sympathize with are rewarded. However, this can also serve as an open path for a possible sequel. For example, in the 1977 film Star Wars, Luke Skywalker defeats the Galactic Empire by destroying the Death Star; however, the story's happy ending has consequences that follow in The Empire Strikes Back. The concept of a permanent happy ending is specifically brought up in the Stephen King fantasy/fairy tale novel The Eyes of the Dragon which has a standard good ending for the genre, but simply states that "there were good days and bad days" afterwards.
A happy ending only requires that the main characters be all right. Millions of innocent background characters can die, but as long as the characters that the reader/viewer/audience cares about survive, it can still be a happy ending. Roger Ebert comments in his review of Roland Emmerich's The Day After Tomorrow: "Billions of people may have died, but at least the major characters have survived. Los Angeles is leveled by multiple tornadoes, New York is buried under ice and snow, the United Kingdom is flash-frozen, and much of the Northern Hemisphere is wiped out for good measure. Thank god that Jack, Sam, Laura, Jason and Dr. Lucy Hall survive, along with Dr. Hall's little cancer patient."
The presence of a happy ending is one of the key points that distinguish melodrama from tragedy. In certain periods, the endings of traditional tragedies such as Macbeth or Oedipus Rex, in which most of the major characters end up dead, disfigured, or discountenanced, have been actively disliked. In the seventeenth century, the Irish author Nahum Tate sought to improve William Shakespeare's King Lear in his own heavily modified version in which Lear survives and Cordelia marries Edgar. Tate's version dominated performances for a century and a half and Shakespeare's original was nearly forgotten. Both David Garrick and John Philip Kemble, while taking up some of Shakespeare's original text, kept Tate's happy ending. Edmund Kean played King Lear with its tragic ending in 1823, but failed and reverted to Tate's crowd-pleaser after only three performances. Only in 1838 did William Macready at Covent Garden successfully restore Shakespeare's original tragic end – Helen Faucit's final appearance as Cordelia, dead in her father's arms, became one of the most iconic of Victorian images and the play's tragic end was finally accepted by the general public. Most subsequent critics have not found Tate's amendments an improvement, and welcomed the restoration of Shakespeare's original. Happy endings have also been fastened – equally, with no lasting success – to Romeo and Juliet and Othello.
There is no universally accepted definition of what a happy ending is; such definitions can considerably vary with time and cultural differences. An interpretation of The Merchant of Venice's forced conversion of Shylock to Christianity is that it was intended as a happy ending. As a Christian, Shylock could no longer impose interest, undoing his schemes in the play and ending the rivalry between him and Antonio, but more important, contemporary audiences would see becoming a Christian as a means to save his soul (cf. Romans 11:15). In later times, Jews (and non-Jewish opponents of anti-Semitism) strongly objected to that ending, regarding it as depicting a victory for injustice and oppression and as pandering to the audience's prejudices.
Similarly, for Sixteenth Century audiences, the ending of The Taming of the Shrew - a formerly independent and assertive woman being broken and becoming totally submissive to her husband - might have counted as a happy ending, which it would not under present-day standards of women's place in society (see The Taming of the Shrew#Sexism controversy).
Most interpretations of the legend of Don Juan end with the protagonist rake being dragged off to Hell, in just retribution for his many sins (for example, the ending of Mozart's Don Giovanni). However, José Zorrilla - whose 1844 play Don Juan Tenorio is the version most well-known in the Spanish-speaking world - believed that a story should never end sadly, and must always have a happy ending. In Zorrilla's depiction, Don Juan is saved at the last moment from the flames of Hell by the selfless pure love of Doña Inés, a woman whom he wronged but who forgave him; she had made a deal with God to offer her own blameless soul on behalf of Don Juan's – thus redeeming Don Juan and taking him with her to Paradise.
The Octoroon, a 1859 anti-slavery play by Dion Boucicault, focuses on the tragic love between the white George Peyton and the Octoroon girl Zoe. Her one-eighth Black ancestry is enough to prevent their marrying. In the American society of the time, it would have been unacceptable to present a play ending with a mixed-race couple consummating their love. Rather, the play ends with Zoe taking poison and dying, the grief-stricken George at her side. However, when the play was performed in England, where prejudice was less strong, it was given a happy ending, culminating with the young lovers happily getting together against all odds.
In 17th Century Italy, Francesco Cavalli wrote the opera Didone, based on Virgil's Aeneid (Book 4 in particular) and set to a libretto by Giovanni Francesco Busenello. However, Busenello's libretto changed the tragic ending provided by Virgil, in which Dido commits suicide after Aeneas abandons her. In Busenello's version Iarbas, King of the Getuli, shows up in the nick of time to save Dido from herself, and she ends up happily marrying him.
A Times review of The Spy Who Came in from the Cold strongly criticized John le Carré for failing to provide a happy ending, and gave unequivocal reasons why in the reviewer's opinion (shared by many others) such an ending is needed: ""The hero must triumph over his enemies, as surely as Jack must kill the giant in the nursery tale. If the giant kills Jack, we have missed the whole point of the story.
George Bernard Shaw had to wage an uphill struggle against audiences, as well as some critics, persistently demanding that his "Pygmalion" have a happy ending, i.e. that Professor Higgins and Eliza Doolitle would ultimately marry. To Shaw's great chagrin, Herbert Beerbohm Tree who presented the play in London's West End in 1914 had sweetened the ending and told Shaw: "My ending makes money; you ought to be grateful. Your ending is damnable; you ought to be shot." The irritated Shaw added a postscript essay, "'What Happened Afterwards", to the 1916 print edition, for inclusion with subsequent editions, in which he explained precisely why in his view it was impossible for the story to end with Higgins and Eliza marrying. Nevertheless, audiences continued wanting a happy ending also for later adaptations such as the musical and film "My Fair Lady".
In numerous cases, Hollywood studios adapting literary works into film added a happy ending which did not appear in the original.