The Mandarin is a fake. When Tony tracks the broadcasts to Miami, he finds that "the Mandarin" is Trevor Slattery (Ben Kingsley), an English actor who doesn't know what is being done in his name. The real mastermind is Aldrich Killian, who invented the terrorist to hide the fact that Extremis test subjects were exploding. He also plans to control both the "terror" and the response to it, partly through the compromised Vice President.
The origin. The 1999 prologue plants everything. Tony blew off Killian and slept with Maya, then ignored both of them, which creates the demons of his opening line. Maya works with Killian, then turns against him, and Killian kills her.
The climax. Pepper is kidnapped and injected with Extremis, and Killian takes the President hostage on an oil rig. Tony and Rhodey attack together, and Tony calls in the whole Iron Legion with the "House Party Protocol." In a key reversal, Pepper, now Extremis-powered, kills Killian and saves Tony instead of being rescued by him.
The ending. Tony has Extremis stabilized in Pepper, destroys his suits with the \"Clean Slate Protocol\" as a gift to her, has the shrapnel removed and throws the arc reactor into the sea. The narration, it turns out, has been Tony talking to Bruce Banner, who fell asleep. Tony's final statement, \"I am Iron Man,\" changes meaning from the first film: it was once a public confession of an alter ego, and now it says the hero never lived in the suit.