Deus ex machina (/ˌdəs ɛks ˈmækɪnə, - ˈmɑːk-/ DAY-əs ex-MA(H)K-in-ə,[1] Latin: [ˈdɛ.ʊs ɛks ˈmaːkʰɪnaː]; plural: dei ex machina; English "god out of the machine")[2][3] is a plot device whereby a seemingly unsolvable problem in a story is suddenly and abruptly resolved by an unexpected and unlikely occurrence.[4][5] Its function is generally to resolve an otherwise irresolvable plot situation, to surprise the audience, to bring the tale to a happy ending, or act as a comedic device.[6]

Deus ex machina in Euripides' Medea, performed in 2009 in Syracuse, Italy; the sun god sends a golden chariot to rescue Medea