The deus ex machina is a plot device used to resolve a problem in a literary work. Generally, it is something that does not realistically fit into the story, such as lightning conveniently striking and getting rid of an inconvenient character. Some authors dissaprove of the use of the deus ex machina, whereas others, such as Socrates, Euripides, and Stephen King use it incessantly throughout their works.Aristotle in his Poetics, was the first one to condemn the use of this device.
Deus ex Machina is a Latin phrase which literally translates, "deity from out of a machine". It is a reference to a theatrical device in Roman and Greek plays. In some Roman and Greek dramatic works, if a character in the play found themselves in an impossible situation, an actor playing the role of a deity was lowered from a machine (a crane) onto the stage to resolve the plot.
As a contemporary artistic device it is either used to resolve a difficult plot by means that are apparently artificial, in a mechanical sense or in a metaphysical sense, or it is used as a way to indicate an inherent metaphysical presence within the underlying system or structure of something mechanical.