A person or thing that suddenly resolves a problem or a device providing a contrived resolution in a play. In Greek, or Roman dramas, this was a device by which a god appeared on the stage at a crucial moment to help solve the dilemma. Now it refers to a person or thing that solves a problem in a drama by some artificial or abrupt means.
The expression has its origin in ancient Greek theater, especially in certain plays by Euripides. When the complexities of plot and character appeared incapable of resolution, a god was set down on stage by a mechanical crane or derrick to sort out things and make them right.
The appearance, or epiphany, of the god or goddess was interpreted by some critics, notably the Roman poet Horace, as proof that Euripides (or some other dramatist) had so piled up the complications in the plot that he needed divine intervention to untangle the situation. The resultant meaning has evolved into a situation where a person or thing that solves a difficulty artificially and abruptly is called a deus, or dea, ex machina.
To provide the story's well-chopped ending, a deus ex machina from the Internal Revenue Department is rolled on to the scene to claim so much in back taxes and penalties that the contestants for the estate have no alternative but to kiss and make up.