Deus ex machina: literally meaning "God in the machine," where an outside force appears at the final moments of a story to solve a seemingly unsolvable problem.
Usually when people talk about deus ex machina, they're criticizing a writer for painting him or herself into a corner, plot-wise, and using any method possible to get out of it. Certainly, it's probably not the most satisfying ending in the world to have a cop suddenly show up and shoot all the bad guys, despite no one having called the cops.
But some deus ex machina works, in my opinion:
When a flood saves the Soggy Bottom Boys at the end of O Brother, Where Art Thou?
When Larry and Ralph are being crucified in The Stand just as the Trashcan Man returns from the desert with the nuclear warhead he'd been sent to find.
When it turns out the magic shop already had the weapon of a god--Olaf's Hammer--before Buffy's big fight with Glory in Buffy the Vampire Slayer.
When John arrives after the gates of hell are opened in Supernatural, giving his son Dean time to find the Colt and save the day.
When Jack sets the island on fire in Lord of the Flies, which allows a naval ship to see the island and rescue all the boys.
Of course, there are times where it doesn't work. For every person that likes the ending of The Stand, there is another person saying, "God saved them? Really, God saved them?"
And as much as I love Hamlet--pirates? Really, pirates? Well, thank goodness that the ending makes up for it.
What examples of deus ex machina work for you, and which ones don't?