Literally "god in the machine" (or "ghost in the machine" as The Police put it), deus ex machina
is a literary device dating back to ancient Greek theater in which divine intervention is employed to get the protagonist out of a sticky situation or untangle an ugly plotline.
A classic example of deus ex machina
is at the end of J.R.R. Tolkien's Lord of the Rings
trilogy. It occurs when Sam and Frodo, inescapably in the midst of Sauron's armies at the top of Mount Doom, are miraculously rescued by giant eagles.More Literary Terms Defined