Deus ex machina, from Latin, means “God from the machine”, referring to the abrupt resolution of a problem or conflict with some contrived, artificial plot device that steps in without any previous warning.
Usually the use of a deus ex machina frustrates audiences, who have invested time and energy in the characters of a story and prefer to see a more satisfying, natural resolution to the struggles of those characters. Lucky breaks often happen in real life, but unearned luck doesn’t make for a very good story.
A deus ex machina is often the mark of lazy, unimaginative writing. Writers of story songs beware.