Deus ex machinamight be one of the world's oldest plot devices. The ancient Greek playwright Euripides used this device in nearly half of his plays that still exist - and based on the writings of Aristotle and others, we know that Euripides was considered one of the foremost writers of his day. If that's the case, then we can probably safely assume that a deus ex machina was used in a lot of Greek plays - the same source that most of our modern narrative techniques come from.
Deus ex machina (pronounced day-oos x mach-ee-na) means "god out of the machine" or "god from the machine" in Latin. As a literary device, it is where, at the conclusion of the narrative, a climax and ending simply presents itself. In Euripides' play, it would have been a god causing something to occur, which triggers the ending - this is where we get the name.
Essentially, the deus ex machina is when, at the end of a story, an extraneous element appears, having nothing to do with the main characters or the central plot, that solves all the problems in the narrative and effectively ends the story.
So why is this bad for modern readers?
In modern narratives, readers expect that the writer will solve the narrative (the story-wide tension building leading from the instigating incident to the climax) by building a set of clues into the main characters' actions and personalities. If you have a murder mystery, you want your main character to solve the problem - not a random cop you've never seen before show up to explain what really happened.
Even Sherlock Holmes can sometimes be considered a deus ex machina, because some of the lesser stories don't have enough clues in place for Holmes to really be able to solve the case, so his explanations just sound like a justification for the ending. "Miracle" endings - where things suddenly change for the better, like incurable cancer suddenly goes into remission despite no effort on anyone's doing, are also deus ex machina.
Basically, when deus ex machina happens, it breaks the readers' trust in the writer, because the writer wasn't able to solve the narrative organically and from within the story. We go to stories to escape from reality, but not to the point where reality doesn't hold.
In essence, the deus ex machina breaks the reader's willing suspension of disbelief - the act of believing in a story's truth, even when the reader knows it's just a story. Since this break happens only in the final moments of a story, the deus ex machina generally ruins the entire narrative for the reader. It is the considered one of the weakest narrative endings.