Deus ex machina

Deus ex machina (/ˈdəs ɛks ˈmækɪnə, ˈmɑːk-/ DAY-əs ex-MA(H)K-in-ə; Latin: [ˈdɛ.ʊs ɛks ˈmaːkʰɪnaː]; plural: dei ex machina; 'God from the machine') is a plot device whereby a seemingly unsolvable problem in a story is suddenly or abruptly resolved by an unexpected and unlikely occurrence. 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.