Lately the phrase has had a still wider use: the computer game Deus Ex (1999), for example, treats machina as "machine" and uses the phrase to refer to a being of godlike power emerging out of machines, and more generally, out of the chaotic complexity of a society gone mad.
There's nothing wrong with using a popular phrase in such an evocative way: but we're not looking at how it is used nowadays. We're going to look at where the phrase came from.
People who are a bit better informed will go, "Ah! Well, you see, this was originally a term for a stage prop used in ancient Greek tragedy." For example. In Euripides' play Medea (431 BCE), when Medea escapes with the aid of the Sun god, she appears suspended above the stage on a crane, designed to give the impression that she is flying. In Sophocles' play Philoctetes, when Heracles appears at the end to set everything to rights he too appears on the crane. The ancient term for this was deus ex machina, quite literally "a god from a crane": so it referred originally to an ancient Athenian staging technique.
Except, oops, that's not it either. Deus ex machina isn't Greek: it's a Latin phrase. Euripides and Sophocles may well never have even heard of Latin, let alone used it for a stage device.
Most dictionaries of literary terms and the like gloss over this point: why on earth do we use a Latin term for a Greek theatrical device? Here's the definition in J. A. Cuddon's Penguin Dictionary of Literary Terms and Literary Theory (1991):
(L[atin] 'god out of a machine') In Greek drama a god was lowered onto the stage by a mēchanē so that he could get the hero out of difficulties or untangle the plot. ...Well, this is accurate so far as it goes. But it doesn't explain why we're using a Latin phrase when we talk about Greek drama.
Much more inaccurately, Wikipedia describes the earliest use of the phrase as follows:
Aristotle was the first to use deus ex machina as a term to describe the technique as a device to resolve the plot of tragedies.Aristotle did not write in Latin. (Hilariously, the supposed authority given for this claim is not Aristotle as you might expect, but an article in a machine science journal! Happily, the authors of the actual article are sensible enough not to make this silly claim.) Elsewhere the Wikipedia article claims
Such a device was referred to by Horace in his Ars Poetica (lines 191–2), where he instructs poets that they should never resort to a "god from the machine" to resolve their plots...Those quotation marks sure make it sound like Horace uses the phrase "god from the machine", right? Well, that's not true either.
In fact, no actual ancient Roman text ever used the phrase. Not one. I've checked.
Now, the Greek counterpart of this phrase was reasonably widespread. It appears in several Byzantine lexicons as a proverbial phrase (in full, apo mēchanēs theos epiphaneis, "a god who has appeared from a crane"). And a couple of ancient Latin authors do echo the Greek proverb: Pliny the Elder's Natural History book 36 (1st cent. CE) refers to the "portion of immortal gods, in common with humankind, hanging on a crane and applauding its own peril"; and Statius' Thebaid (late 1st cent. CE) refers to gods as "hanging on a crane of the sky".
But still no verbatim use of deus ex machina. That phrase didn't come along until the modern era.
The Oxford English Dictionary is a better guide than most. It lists a 1697 book, John Sergeant's Solid Philosophy Asserted, as the earliest use of the phrase. But that's just the earliest use of the phrase in English: in other European languages, several authors used the phrase earlier on.
In 1675 Theodosius Preu, a Swiss, published a pamphlet entitled Deus ex machina; in 1658 Hyacinth de Chalvet, a French Dominican preacher at Toulouse, used the phrase in his book De scientia Dei; and in 1622 the Venetian scholar Paolo Beni, a.k.a. "Eugubinus", used the phrase in a 1622 commentary on Aristotle's Poetics;
But the very earliest verbatim appearance of the phrase comes from 1561, in an edition of Horace's poetry edited by the great French scholar Denis Lambin (reprinted 1566). His note on Art of Poetry 191, at page 199a, reads
"Nec deus intersit", &c.] Aristot. lib. περὶ ποιητ. scribit utendum esse machina, seu machinatione: id est, deum esse adhibendum à machina, ad ea, quae sunt extra fabulam, expedienda: quae uel antea facta sunt, neque hominem scire fas est, uel postea futura sunt, & praedictionem, ac nunciationem desiderant.
"Nor should a god appear", etc.] Aristotle in his book the Poetics writes that this was done with a crane, or a mechanism: that is, a god would be introduced on a crane in order to resolve matters that lay outside the plot, when they wanted a foretelling or announcement of things that had happened previously or were going to happen, but which were not lawful for a mortal to know.Lambin goes on to quote supporting evidence from Aristotle (Poetics 1454a.37-b6, Metaphysics 985a.18-21), Plato (Cratylus 425d), and Cicero (On the nature of the gods 1.53).
But you'll notice that even in this passage, Lambin doesn't use the phrase. For that, we have to turn to the book's index, which refers back to this discussion.
It is very implausible that deus ex machina caught on from an index entry. A much stronger candidate for the source that inspired de Chalvet, Preu, and Sergeant is Beni's 1622 Poetics commentary. Beni probably knew Lambin's book (he was Venetian, and Lambin's book was published in Venice), but his work is independent: he quotes the same passages from Cicero's On the nature of the gods and Aristotle's Metaphysics that Lambin does, but he was not just copying. Beni's texts have different punctuation and capitalisation, and he gives his own Latin translation from Aristotle's Greek.
When Beni introduces the phrase, he is quoting Cicero discussing miracles and divine interventions:
...Quam sententiam egregie nobis expressit ac declarauit M. Tullius in 1. de Natura Deorum, apud quem Velleius sic irridet eos qui in Vniuersitatis molitione Deum adhiberent. Quod quia (inquit) quemadmodum Natura efficere sine aliqua mente possit, non videtis, ut Tragici Poetae, cum explicare argumenti exitum non potestis, confugitis ad Deum. Atque hinc vulgatum prouerbium ἀπὸ μηχανῆς θεὸς ἐπιφανείς, hoc est Deus ex machina apparens.
...This sentiment was also expressed for us nobly by Marcus Tullius [Cicero], in book 1 of his On the nature of the gods. There, Velleius makes fun of those who admit the possibility of God intervening in the universe. He says: "But since you don't see how Nature can achieve it without some kind of mind, you do as the tragic poets do: when you can't resolve the plot, you resort to a god." This is where we get the popular proverb ἀπὸ μηχανῆς θεὸς ἐπιφανείς, that is, "a god appearing from a crane".I'd bet a moderate sum of money that the other 17th century writers who use the phrase got it from Beni. But strictly from the point of view of who first used the exact phrase deus ex machina, Lambin is the winner.