From TV Tropes:
~~~~~~~~~~~~~
A Deus Ex Machina is an outside force that solves a seemingly unsolvable problem in an extremely unlikely (and, usually, anticlimactic) way. If the secret documents are in Russian, one of the spies suddenly reveals that they learned the language. If the writers have just lost funding, a millionaire suddenly arrives, announces an interest in their movie, and offers all the finances they need to make it. If The Hero is dangling at the edge of a cliff with a villain stepping on his fingers, a flying robot suddenly appears to save him.
The term is Latin for god out of the machine, and has its origins in Greek theater. It refers to situations in which a crane (machine) was used to lower actors or statues playing a god or gods (deus) onto the stage to set things right. It has since come to be used as a general term for any event in which a seemingly fatal plot twist is resolved by an event never foreshadowed or set up.
"If you say in the first chapter that there is a rifle hanging on the wall, in the second or third chapter it absolutely must go off. If it's not going to be fired, it shouldn't be hanging there."
— Playwright Anton Chekhov (From S. Shchukin, Memoirs. 1911.)
Thornton Reed: "Take this, Dag."
Dr. Rick Dagless M.D.: "What is it?"
Thornton Reed: "Something that might come in handy."
— Garth Marenghi's Darkplace, "Scotch Mist"
"Honestly, what kind of situation would require the use of a pair of fake arms and a remote-controlled wheelchair? Only, I imagine, a completely ludicrous one!"
— Father Ted