Deus ex machina — god from the machine, after the crane that lowered gods onto the Greek stage — is a resolution arriving from outside the story's established terms. The defining faults are two and they must both be present: the agency was not set up, and the protagonist did not cause it. A rescue by a character introduced two hundred pages earlier for another purpose is legitimate plotting; the same rescue by someone the reader has never met is not.
Also written as deus ex machina ending, god from the machine.
Set-up is the whole defence
Almost any resolution can be earned if its means were established early enough and unobtrusively enough. The practical rule is that the capability, ally or coincidence must appear before the reader knows it will matter, and preferably while it is doing something else. Introducing it in the same chapter it saves the day is what turns a plant into a contrivance.
Coincidence in versus coincidence out
The usable convention is that coincidence may create problems but not solve them. A chance meeting that starts the trouble is accepted without complaint; the same chance meeting resolving it is not, because it makes the protagonist's efforts irrelevant. This asymmetry is the single most useful test available for whether a plot turn will be forgiven.
Its legitimate uses
The device is not always a fault. Classical drama used it deliberately to assert divine order, and modern comedy and satire deploy it knowingly, where the arbitrariness is the point. What distinguishes a use from a failure is whether the text acknowledges the arbitrariness — a book that shrugs at its own rescue is making a joke; one that presents it as satisfying is making a mistake.
Where to see it working
Medea — Euripides
The original stage machinery, used deliberately to assert a divine order the human plot cannot overrule.
The War of the Worlds — H. G. Wells
Bacteria resolve the invasion, but the mechanism is seeded throughout and the point is human irrelevance.
Lord of the Flies — William Golding
The naval officer's arrival is deliberately arbitrary, and the text makes the arbitrariness the final irony.
How it goes wrong
Introducing the saving capability in the chapter where it saves the day.
Using coincidence to solve a problem rather than to create one.
Presenting an arbitrary rescue as emotionally satisfying rather than acknowledging it.
Confusing a well-planted ally with a contrivance; set-up is what separates them.
Related terms
Chekhov's Gun
The principle that a conspicuously introduced detail must later be used, and anything never used should be removed.
Foreshadowing
Placing information early so a later development feels inevitable in retrospect without being predictable in advance.
MacGuffin
An object everyone in the story wants whose specific nature is irrelevant, existing to generate pursuit rather than meaning.
Plot Armour
The reader's sense that a character cannot come to harm because the narrative requires them, which drains tension.
Not sure which shelf your own manuscript belongs on? Run it through the book genre and comp title finder — free, no sign-up.