The term deux ex machina, which means "god from a machine" in Latin, was originally used in Classical Greek theater to describe the appearance of gods on the stage--often lowered onto the stage from above in a bucket-like contrivance--who would then sort out all the difficulties in a plot that seemed beyond human powers to resolve.
Shakespeare, for example, used the device in As You Like It when, at the end of the play when all the characters' relationships seem at an impasse, Hymen appears to pair the appropriate characters so that they can marry.
Although originally a device in theater, deus ex machina has now moved into other genres, including soap operas where a character who dies at one point may miraculously be discovered to be alive and that character is able to resolve an otherwise unresolvable situation. In other genres, short stories or novels, the device is still used to resolve problems that the author might not have been able to solve through proper plot development--for example, when a rich uncle appears, assumed to be dead, who is able to provide solutions to situations that the plot and characters have no way of resolving. In such a case, the use of the deus ex machina device is considered a less-than-skillful way for the author to tie up the loose ends of the plot.