A deus ex machina ( /ˈdeɪ.əs ɛks ˈmɑːkiːnə/ or /ˈdiːəs ɛks ˈmækɨnə/ DAY-əs eks MAH-kee-nə; Latin: "god from the machine"; plural: dei ex machina) is a plot device whereby a seemingly unsolvable problem is suddenly and abruptly solved with the contrived and unexpected intervention of some new event, character, ability, or object. It can be roughly translated as "God made it happen," with no further explanation, and, depending on usage, is primarily used to move the story forward when the writer has "painted himself into a corner" and sees no other way out. However, in other cases, it is used to surprise the audience, or, commonly influenced by editors and/or publishers, to bring a happy ending into the tale.
Read more about Deus Ex Machina: Linguistic Considerations, Ancient Uses, Criticism