Deus ex Machina literally means God in the machine, and it comes from old Greek and Roman plays where the story conflict, (i.e. the Dramatic Question) was resolved by somebody playing a god being lowered by ropes (i.e. the machine) to the stage to sort out all the characters’ problems at the end of the play.
It has come to have a wider meaning nowadays, and it means any artificial or improbable ending to a story. For example the classic, “I woke up - it had all been a dream,” is Deus ex Machina.
I was explaining this at a writing workshop I was teaching, and one of the students reminded us all of how the 80’s soap opera Dynasty had ended - with aliens coming to whisk off one of the main characters. Now, that’s Deus ex Machina! They weren’t even being subtle about it.
I didn’t watch Dynasty, so I missed that particular gem, but even so I couldn’t help but be aware of the howls of protest that ensued from the viewing public. They knew they’d been ‘had’, and they didn’t like it.
Deus ex Machina doesn’t have to be blatant though. It can be subtle too.
One example would be where, say, the star-crossed lovers couldn’t get together because the woman had previously been hurt so badly that she could never trust again.
But at the end of the novel (about where the author’s nearly at her target word count, and suddenly thinks, Eek, I have to resolve this somehow!!), the character suddenly decides, out of the blue, “Oh, okay, I can trust now,” and gets together with the handsome hero for no real reason except the story demands it.
As I explain in Sacred Contract, you have a responsibility to your reader, and a contract with them.
Using a Deus ex Machina totally blows that contract up.
To honour the contract, in the above example, the story would have to follow the woman’s Character Arc (i.e. how she grows and develops during the story) as she gradually found the courage to trust again. There would have to be reason for her to trust the erstwhile lover (maybe he proves himself somehow). Then we could believe it, and then it would be satisfying.
It’s much harder to write this way, of course. (But hey, if it was easy everybody would be doing it!)