Deus ex machina

 A deus ex machina ( or, literally "god from the machine") is a plot device in which a person or thing appears "out of the blue" to help a character to overcome a seemingly insolvable difficulty.

Linguistic considerations
The Latin phrase "deus ex machina" comes to English usage from Horace's Ars Poetica, where he instructs poets that they must never resort to a god from the machine to solve their plots. He is referring to the conventions of Greek tragedy, where a crane (mekhane) was used to lower actors playing a god or gods onto the stage. The machine referred to in the phrase could be either the crane employed in the task, a calque from the Greek "god from the machine" ("," apò mēkhanḗs theós), or the riser that brought a god up from a trap door.

Ancient uses
The Greek tragedian Euripides is often criticized for his frequent use of the deus ex machina. More than half of Euripides' extant tragedies employ a deus ex machina in their resolution and some critics go so far as to claim the mekhane was a Euripidean invention. For example, in Euripides' play Alcestis, the eponymous heroine agrees to give up her own life in order to spare the life of her husband, Admetus. At the end Heracles shows up and seizes Alcestis from Death, restoring her to life and to Admetus. A more frequently cited example is Euripides' Medea in which the deus ex machina is used to convey Medea, who has just committed murder and infanticide, away from her husband Jason to the safety and civilization of Athens. In Aristophanes' play Thesmophoriazusae the playwright parodies Euripides' frequent use of the crane by making Euripides himself a character in the play and bringing him on stage by way of the mekhane.

Aristotle criticised the device in his Poetics, where he argued that the resolution of a plot must arise internally, following from previous action of the play: In the characters too, exactly as in the structure of the incidents, [the poet] ought always to seek what is either necessary or probable, so that it is either necessary or probable that a person of such-and-such a sort say or do things of the same sort, and it is either necessary or probable that this [incident] happen after that one. It is obvious that the solutions of plots too should come about as a result of the plot itself, and not from a contrivance, as in the Medea and in the passage about sailing home in the Iliad. A contrivance must be used for matters outside the drama—either previous events which are beyond human knowledge, or later ones that need to be foretold or announced. For we grant that the gods can see everything. There should be nothing improbable in the incidents; otherwise, it should be outside the tragedy, e.g. that in Sophocles’ Oedipus. Aristotle praised Euripides, however, for generally ending his plays with bad fortune, which he viewed as correct in tragedy, and somewhat excused the intervention of a deity by suggesting that "astonishment" should be sought in tragic drama: "Irrationalities should be referred to what people say: that is one solution, and also sometimes that it is not irrational, since it is probable that improbable things will happen."

Medieval uses
The earliest use of deus ex machina in a murder mystery occurs in the Arabian Nights tale of "The Three Apples", near the middle of the story. After discovering the dead body of a young woman, Harun al-Rashid orders his vizier, Ja'far ibn Yahya, to solve the crime and find the murderer within three days or else he will have him executed instead. Ja'far, however, fails to find the murderer before the deadline. Just when Harun is about to have Ja'far executed for his failure, a deus ex machina occurs when the murderer suddenly reveals himself, claiming to be the woman's husband.

Modern criticism
Following on from Aristotle's example, Renaissance critics continued to view the deus ex machina as an inept plot device, although it continued to be employed by Renaissance dramatists; Shakespeare used the device in Pericles, Hamlet, and The Winter's Tale. Towards the end of the 19th century, Friedrich Nietzsche criticised Euripides for making tragedy an optimistic genre via use of the device and was highly skeptical of the "Greek cheerfulness" this prompted and what he viewed as the plays' "blissful delight in life." The deus ex machina as Nietzsche saw it was symptomatic of Socratic culture that valued knowledge over Dionysiac music and ultimately caused the death of tragedy: But the new non-Dionysiac spirit is most clearly apparent in the endings of the new dramas. At the end of the old tragedies there was a sense of metaphysical conciliation without which it is impossible to imagine our taking delight in tragedy; perhaps the conciliatory tones from another world echo most purely in Oedipus at Colonus. Now, once tragedy had lost the genius of music, tragedy in the strictest sense was dead: for where was that metaphysical consolation now to be found? Hence an earthly resolution for tragic dissonance was sought; the hero, having been adequately tormented by fate, won his well-earned reward in a stately marriage and tokens of divine honour. The hero had become a gladiator, granted freedom once he had been satisfactorily flayed and scarred. Metaphysical consolation had been ousted by the deus ex machina. Nietzsche argues that the deus ex machina creates a false sense of consolation that ought not to be sought in phenomena and this denigration of the plot device has prevailed in critical opinion. Some 20th-century revisionist criticism suggests that the deus ex machina cannot be viewed in these simplified terms and argues rather that the device allows mortals to "probe" their relationship with the divine. Rush Rehm in particular cites examples of Greek tragedy in which the deus ex machina serves to complicate the lives and attitudes of characters confronted by the deity whilst simultaneously bringing the drama home to its audience.

Modern uses
In fiction writing, the phrase has been extended to refer to a sudden and unexpected resolution to a seemingly intractable problem in a plot-line, or what might be called an "Oh, by the way..." ending. Some critics think that a deus ex machina is generally undesirable in writing and often implies a lack of skill on the part of the author because it does not pay due regard to the story's internal logic and is often so unlikely that it challenges suspension of disbelief, allowing the author to conclude the story with an unlikely, though more palatable, ending. A well-known modern example of deus ex machina occurs in the Michael Crichton book The Andromeda Strain: the pathogen referred to in the title is suddenly rendered non-lethal by a random mutation which apparently affects every existing virus particle instantaneously.

Sometimes the unlikeliness of the deus ex machina plot device is employed deliberately. An example is in Bertolt Brecht's epic musical The Threepenny Opera (1928), in which a "riding messenger of the king" appears in the last moment, stops the execution of the story's criminal anti-hero Mack the Knife and bestows an inheritable title of nobility on him. The very absurdity of this serves to underscore the great lack of generosity and selflessness in the capitalist reality that the story dramatises. Another example is in the film Adaptation, in which a character comments on the cheapness and laziness of a deus ex machina ending, only to have one occur ironically during the climax of the film. Monty Python's Life of Brian uses deus ex machina for comic effect when Brian falls off a tall tower while evading the Romans only to be picked up by aliens, who fly into outer space to evade a pursuing force, get shot down, and crash back into Jerusalem, where Brian climbs out of the wreckage free of injuries and continues the chase. In the episode "Thank God It's Doomsday" of the animated television series The Simpsons, in which Homer is the only human being to ascend to Heaven after the Apocalypse, he begs God to undo what He did, and in doing so, God exclaims, "Deus ex machina!" as an incantation and literally reverses the end of the world. The Simpsons has been known to end many of its episodes with a deus ex machina. Also, in the Spider-Man graphic novel "Reign," Spider-Man's narration boxes poetically describe the nature of a deus ex machina as the body of Dr. Octopus descends on the Sinner Six to rescue him.

And it was all a dream
One deus ex machina of note is plot reversals ascribed to dreams - so called "dream seasons", or, in at least one case, an entire "dream series", where the author of a series discards already-written matter from the timeline by saying that it was all a character's dream. Examples are:
 * In Dallas, the well-known return of Bobby Ewing, where he died at the end of season eight, but nonchalantly said "Good morning!" to Pamela Ewing in the last episode of season nine (in 1986), following her long nightmare.
 * In the series Newhart (October 25, 1982 - May 25, 1990), which was Bob Newhart's follow-on to his original series The Bob Newhart Show (September 16, 1972 - April 1, 1978). The final episode of Newhart reveals that the entire follow-on series was a dream of Newhart's character Dr. Robert Hartley, completely contained in the original series. This comic use of the device depended on the previous use in the show Dallas (mentioned previously) for some of its comic charm.
 * In the Gerry Anderson UFO series episode Ordeal, Foster is abducted by aliens in a UFO, and rescued; but the end of the episode shows that the abduction was only a dream of Foster's while he was unconscious in Moonbase because of going under a hot shower while affected by medication.
 * In Married... with Children, Peggy Bundy becomes pregnant in the sixth season, in part to accommodate the real-life pregnancy of Peggy's portrayer, Katey Segal. After Segal suffered a miscarriage, the storyline was rewritten so that the preceding episodes featuring the pregnancy were Al Bundy's dream.