The literary concepts of deus ex machina and eucatastrophe are not synonymous. Both are sudden reversals at the climax of a narrative where things are looking grim for our protagonists, but their details do not overlap — not even enough to call eucatastrophe a subset of deus ex machina.
Deus ex machina, “god from the machine,” is a term originating from ancient Greek theater. When the heroes were in an impossible situation and the play was out of time, a god character would be lowered from the rafters above the stage and hand them victory. Today this is widely recognized as flawed storytelling. It breaks the integrity of the story to have an external force resolve the conflict: nothing leading up to this point actually mattered. It feels arbitrary, as if the storyteller had no plan.
The eu (good) catastrophe, the happy disaster, also saves our heroes from an impossible situation. But they are saved because the outcome of their failure is unexpected success. It is not external, but a direct consequence of the story pieces already in play.
Since Tolkien defined the term eucatastrophe in On Fairy Stories, an explicitly religious essay defending fantastic sub-creations that point to the resurrection story as suitable work for Christians, I consider it disingenuous to separate the term from a Catholic mindset when defining it (as Wikipedia has done, and I assume some literature courses). When Tolkien proposed the term eucatastrophe, we know from the text and his letters that he was thinking of Christ. As a Catholic, he believed that Christ’s complete defeat and death was a necessary part of the process that saves mankind.*
In a eucatastrophe, what looks like a huge loss is the reason that our heroes succeed. It’s not merely an emotional sequence of almost-defeat and then success, but a causal link.
The archetypal example of the eucatastrophe in Tolkien’s work is not the eagles, but Gollum biting the ring from Frodo’s hand. (The eagles are arguably a deus ex machina: with the lines as I draw them, I’d argue that Tolkien used both literary devices to explore his theme of grace.)
The eucatastrophe is not arbitrary, but happens as the storyteller planned it all along. The interference of supernatural grace is not a negation of the characters’ agency but comes in to use the antagonist’s actions, intended to harm the heroes, for their good instead (as in the story of Joseph, Genesis 50:20).
A story with a eucatastrophe gives readers the power to keep going through it instead of engaging in avoidant behavior when they face real difficulties that seem impossible. It teaches them a thought pattern in which growth, better than mere escape, will give their darkest hours meaning in retrospect.
If you remain unconvinced, let us agree to disagree as storytellers and leave it at this:
“Deus ex machina works when it is the point.” Film Crit Hulk
* Footnote… I am summarizing recklessly here, since theologically this is one of those Big Deals that gets subtle quickly. See any Catholic commentary on Luke 24:26 for the information I consider relevant to this argument, which is Tolkien’s intellectual environment.