1. What it means: deus ex machina is Latin for “god in the machine.” It’s a literary term that dates back to the time of the ancient poet Horace. Greek tragedies would sometimes resolve plays by having one of the gods come down from Olympus (on a crane, hence the term machine) and tell the characters how to resolve their problems and conflicts. Today, the term is used to describe a plot contrivance where someone or something other than the main character(s) brings about the resolution of the story.
2. What it’s not: a catch-all phrase to describe any plot twist people don’t like. For instance, the plot twist for M. Night Shyamalan‘s Signs has been rightly reviled by audiences, but it’s not deus ex machina. It just made the invading aliens look stupid. The characters figured out the aliens’ weakness, so they were actively involved in the story’s resolution.
Help arriving at an opportune time is not necessarily deus ex machina if the characters had something to do with it. For instance, in the classic Western Stagecoach, the cavalry arrives while the stagecoach is attacked by Apache warriors. It’s not deus ex machina because the characters had sent a message to the cavalry before they set out on that dangerous leg of the journey.
3. The key to avoiding deus ex machina: active characters making tough choices, no matter how difficult or impossible they seem. Don’t take the resolution out of the hands of the main character(s). How the story ends should reflect choices the characters have made throughout the story.
Think about the ending of Gone With The Wind–it would have been easy for author Margaret Mitchell to give Scarlett everything she said she wanted because of Melanie’s convenient death. Now think about the choices Scarlett made throughout the story, and how they converge in that final scene.
I’ve seen the ending of Shakespeare in Love cited as a deus ex machina, when it’s not. Queen Elizabeth does not make the choices for Will and Viola, she only articulates the situation. While circumstances that existed at the beginning of the story force them apart (he’s already married, she’s forced into an arranged marriage), they still achieve their goals. Will sets out to write a play that shows the true nature of love and succeeds. Viola sets out to become a player in the theater and experience true love and succeeds. They both knew the limitations of their relationship from the beginning. They made the choice to proceed when they knew it couldn’t last.
Even if your main character doesn’t achieve a stated goal, make that resolution his or her choice, i.e. the ending of Raiders of the Lost Ark.
4. You can get away with it in the middle of the story–sometimes. Vladimir Nabokov used deus ex machina in his novel Lolita by having main character Humbert’s wife die in a car accident after his failed attempt to murder her. Readers will accept a convenient twist of fate far more in the midst of the story than at the end–especially when the convenient twist of fate sparks a new and engrossing direction for the story. In this case, Humbert running away with his nubile stepdaughter.
5. You can get away with it at the end of the story–rarely. The end of Jurassic Park is often cited as a case of deus ex machina, since the characters only escape a Velociraptor attack by the timely arrival of a Tyranosaurus rex. The reason it works is because even though the chances of surviving are practically nil, the characters actively try to escape the raptors, they’re not sitting around waiting for help to arrive.
H.G. Wells resolves War Of The Worlds by having the Martian invaders suddenly die off because they did not have an immunity to bacteria on Earth. Again, the deck is stacked so high against mankind that Wells gets away with it. This was less the case in the updated film remake of a few years ago, because technology has advanced so much since the story was originally written.
It works particularly well if it’s part of the joke, as in Dumb & Dumber. The two heroes are forced to walk down the interstate after a break-down and a bus full of bikini models happens by. They turn down the models’ offer of help and walk off, lamenting their bad luck.
7. When in doubt, don’t use deus ex machina. Even though there are exceptions to the rule, it’s usually best to avoid it. Readers like characters who make the tough choices.