The concept of the deus ex machina, or "god from the machine" was a plot device originally created and frequently employed by ancient Greek playwrights. Plays that used it typically concluded with a god, portrayed by an actor, descending to the stage via a crane mechanism. The god then single-handedly resolves all of the conflicts and ties up loose ends regardless of the state they were in prior to his arrival. This was done on purpose to show that only the Gods know how to fix our problems.
In the modern era, the deus ex machina is a plot device used by creators to solve the problems of the story. It differs from its Greek theater origins in that is isn't necessarily a god coming in to save the day, but rather an unknown, and unforeseen element that appears toward the end, often inexplicably, and provides resolution to the narrative. The modern interpretation could involve anything from the sudden and magical rebirth of a character, to the eleventh hour appearance of a new character, or some other random event that solves all of the problems of the story.
The deus ex machina is widely criticized, as it is generally seen as a lazy narrative element capable of resolving any conflict or situation regardless of the previously established logic behind the narrative.