Deus ex machina
"Deus ex machina", pronounced "DAY-us Eks MAH-kih-nuh," is a device in drama or fiction to suddenly introduce a character or event which provides a contrived solution to an otherwise unsolvable problem. Often the "deus ex machina" appears in a chaotic situation and then restores calm and order.
The term translates from the Latin as "god from a machine", a reference to ancient Greek theater, where an actor (a god) would descend from the skies (the top of the theatre) sitting on a device operated by a crude machine. The Greek playwright Euripides (484-406 B.C.) made frequent use of this literary device. A good example is his play Orestes, in which the sun god Apollo prevents the main character Orestes from killing Hermione, the daughter of his enemy, King Menelaus. In contemporary usage, the term can refer to any plot device which appears at the end, and serves no function other than to conclude the story.
It is frequently criticized as an example of poor writing, and as an unimaginative ending; a "cop-out" which allows the author to conclude his work without having to work the various elements of the plot through to their natural conclusion. A well-known example of the Deus ex machina ending is "and then I woke up", a frequent ending in stories written by children.
Ex Machina - science fiction movie