Deus ex machina is a Latin phrase that, translated literally, means "god out of the machine." Um, does that sound terrifying to you?
Before we give you the nitty gritty on how this Latin phrase got its modern meaning, we'll tell you that deus ex machina refers to an outside force swooping into a play, movie, or novel to neatly tie up the plot, resolve conflict, and generally save the day. A deus ex machina is usually viewed as an artificial or contrived way to end things.
Now, the nitty gritty: in ancient Greek plays, an actor playing a god would literally come down onto the stage via a crane-like machine called a mechane and clean up the plot's sticky mess. Hence the phrase "god out of the machine," right? Famous Greek guy Euripides using this device, like in the ending of his play Medea,in which the title character escapes punishment (for killing her own children!) thanks to the intervention of Helios, the god of the sun.
Deus ex machina is a popular device in modern works, too, though usually we don't see actual gods fixing the plot. Check out Shmoop's analysis of the endings of Moliere's Tartuffe, Jane Austen's Northanger Abbey, or Theodore Taylor's The Cay for some example. Or you can head on over to the character analysis for the Lord of the Eagles from The Hobbit.