The deus ex machina, or "god from a machine" is a hack literary trick where the problems of a plot are resolved at the end of the story by the sudden introduction of a new element.
The word is Latin but it has its origins in Greek theater. A Greek diety would be hoisted on stage with a mechane where a scene called for the diety to be in flight.
A simple example of the "Deus ex machina" motiv: In Sophocles' "Philoctetes", Philoctetes is about to hurt Ulysses and his son Neoptolemus, who came to the island of Lemnos, where Philoctetes was...
Stabbing his eyes (heal himself and everyone else). He purifies himself, he must suffer for the pain that he caused the city. He does not kill himself because he will not suffer. He wants to suffer...