Most people like surprises. For this discussion, we’re going to ignore the ones who don’t. We’re also going to skip discussing unpleasant surprises, like finding the last page of a book missing, or a sudden abandonment of the main plot.
So how do you handle a pleasant surprise?
Hint that there might be a surprise coming
You can pull a surprise out of nowhere, but it might not have the impact you’d like if the reader is totally unprepared. When a room full of people hide in the dark and all yell “Surprise! Happy Birthday!” the recipient of the surprise at least knows about the birthday and may have had some inkling of friends behaving oddly in the days leading up to it. Walking into a darkened room to have strangers shout “Happy Birthday” when it was a month ago is just going to prompt confusion, if not fear.
The reaction you want is a smile, or a laugh, not a grimace of terror.
Don’t make it obvious
There’s nothing as anti-climactic as a surprise that everyone saw coming. If you’re going to have a surprise, let it be a surprise. If you’ve had characters gossiping all book that little orphan Roderick bears a curious resemblance to the king, don’t have him be the king’s bastard son. Have him be a shape-shifter bent on usurping the throne, a younger clone of the king, or a boy who bore a coincidental resemblance that rebellious nobles want to use to embarrass the monarchy.
The reaction you want is a smile, or a laugh, not a yawn.
Play by the rules
Just because you didn’t resolve the plot by deus ex machina doesn’t mean that you can pull any old thing out of your hat otherwise. Internal consistency is crucial to any story, and bizarre changes, even at the end, can spoil the whole thing. Don’t break the immersion of your story just to pull a quick “gotcha” moment, no matter how neat a trick you might think it. Imagine in Back to the Future if Marty had never written Doc that note, but the present-day timeline changed anyway. It would have been a cheap trick having Doc live through being shot. But because the note had already been established, Doc taping it back together was a plausible reason for the surprise ending (In fairness to movie-watchers, you knew he was going to pull through somehow, only the means was left up in the air).
The reaction you want is a smile, or a laugh, not outrage over a cheap stunt.