The unsuspecting surprise, the destiny-changing revelation, the true villain’s arrival: the ways a plot can be twisted into a pretzel of surprises are many and varied. Yet they contain a few similar requirements in order to be successful.
First off, the twist has to be something that isn’t easy to predict if you want it to be a surprise. But, at the same time, it can’t be something just randomly tossed in (at least not in the final draft of your story). It has to be a logical part of the story’s progression. The audience has to think, after the initial surprise, Ah hah! I see!
A good way to insure this is to toss in a couple foreshadowing hints along the way. If the main antagonist is someone other than who the protagonist had originally thought, the protagonist (and audience) should still have at least heard about this “new” antagonist’s name at least once earlier in the story. If the big threat the protagonist must thwart turns out to be nothing more than a trap, or a red herring, or both, then before the trap gets sprung, there should at least be a couple hints in the story to at least make the audience (and preferably the protagonist as well) suspect that it might be. If the hero’s sidekick is actually a spy working for the villain, then toss in one or two clues to cause some suspicion (but in a “Nah! It can’t be” way).
Another thing to be careful with is to not throw so many plot twists in that you lose your audience. There is no magic number on that. No “five is good but six is bad” because six might be too few, or three too many. It all depends on the story and how well prepared you are when throwing in the twist(s)—preferably prepared ahead of time, but at minimum before you’ve finished your final edits.
Oh, and uh, like with dating don’t be predictable with any of it. Yeah, I know, goes without saying….