deus ex machina
The phrase deus ex machina (literally "god out of a machine") describes an artificial, or improbable character, device, or event introduced suddenly in a work of fiction or drama to resolve a situation or untangle a plot (e.g. an angel suddenly appearing to solve problems).
The Latin phrase "deus ex machina" has its origins in the conventions of Greek tragedy. It refers to situations in which a mechane (crane) was used to lower actors playing a god or gods onto the stage. Though the phrase is accurately translated as "God from a machine," in literary criticism, it is often translated to "God on a machine." The machine referred to in the phrase is the crane employed in the task. It is a calque from the Greek 'από μηχανής θεός' ápo mēchanēs theós.
The Greek tragedian Euripides is notorious for using this plot device as a means to resolve a hopeless situation. For example, in Euripides' play Alcestis, the eponymous heroine agrees to give up her own life to Death in exchange for sparing the life of her husband, Admetus. In doing so, however, she imposes upon him a series of extreme promises. Admetus is torn between choosing death or choosing to obey these unreasonable restrictions. In the end, though, Heracles shows up and seizes Alcestis from Death, restoring her to life and freeing Admetus from the promises. The first person known to have criticized the device was Aristotle in his Poetics, where he argued that the resolution of a plot must arise internally, following from previous action of the play.