deus ex machina
Deus ex machina is a plot device where (to quote Wikipedia)
a seemingly unsolvable problem in a story is suddenly and abruptly resolved by an unexpected and unlikely occurrence. Its function is generally to resolve an otherwise irresolvable plot situation, to surprise the audience, to bring the tale to a happy ending, or act as a comedic device.
The plot device has been used since at least the time of Ancient Greece (the phrase “deus ex machina” itself is a Latin calque of the original Greek term). Mostly in Ancient Greek tragedies, but occasionally also in comedies, the plot would be resolved by a god character (whence “deus”) descending from above onto the stage by means of a machine like a crane (whence “machina”) and just fixing the whole plot with their supernatural powers. The device was also used by Shakespeare and Molière, and continues to be used regularly in modern film and TV productions, especially big-budget blockbusters where writing a coherent plot was not a high priority.
In serious works, deus ex machina is an extremely unsatisfying plot device. Writers basically use it when they didn’t bother working out their plot properly and have written themselves into an inescapable corner. It’s one of the reasons I’ve struggled to get into the modern Doctor Who – the writers just use deus ex machina to wrap up their tangled nonsensical plots again, and again, and again, and again. It makes me feel like, what was even the point trying to pay attention to this plot, when none of it mattered anyway. (I mean, not every episode relies on the trope, and there’s even one season I’ve watched that actually crafted an intricate plot and didn’t rely on any dei ex machina to solve it. But it’s a recurring problem.)
In comedies, though, I think dei ex machina can actually heighten the comedy (if it’s the kind of comedy that’s already characterised by its sense of the ridiculous or surreal). I don’t have any specific examples to hand, but in a show like The Goodies, where highly improbable, unexpected things happen anyway, it’s really like, what’s one more? Or The Hitchhiker’s Guide to the Galaxy – it’s been too long since I’ve read it, but I feel like that’s the kind of series where dei ex machina would be employed and it’d feel totally fitting.