Logic + Surprise = Wonder
It's the essence and the payoff of any great story (or any other magic trick, for that matter). As the last and the best of the ancient playwrights put it:
"Many things are wrought by Zeus in Olympus
And heaven works much beyond human imagining
The looked-for result will fail to materialize
While heaven finds ways to achieve the unexpected.
So has it happened in this our story."
Euripides wrote these lines for the conclusion of three of his tragedies, including his final, and most terrifying, The Bacchae.
Something to keep in mind next time you hear, "Have a wonderful day!"