At the White House, brainwashed teleporting mutant Nightcrawler tries to assassinate the President of the United States but fails and escapes, leaving a note demanding "mutant freedom now." At Alkali Lake, X-Men member Wolverine finds nothing left of the military base from the previous movie. He returns to Professor Xavier's school for mutants, while fellow X-Men Storm and Jean Grey find Nightcrawler with the help of Xavier and the mutant-tracking machine Cerebro.
Xavier and Cyclops visit Magneto in his plastic prison cell, inquiring about the assassination attempt. Xavier discovers that covert government operative, William Stryker, has been extracting information about Cerebro from a brainwashed Magneto using an injectable drug. Stryker and his assistant Yuriko Oyama capture Cyclops and Xavier and raid Xavier's school. Wolverine kills many of Stryker's men, while Colossus, Rogue, Iceman, Pyro, and most of the students escape through hidden tunnels. Wolverine confronts Stryker, who fails to shed light on Wolverine's past. Iceman helps Wolverine escape, but Stryker's soldiers succeed in sedating six students and breaking into Cerebro.
Impersonating Senator Robert Kelly and Yuriko, the shape-shifting Mystique gains information about Magneto's prison and helps him escape, and also learns of plans of another Cerebro. Wolverine, Rogue, Iceman, and Pyro visit Iceman's parents in Boston. Responding to a 9-1-1 call from Bobby's brother Ronny, the police arrives just as the group is leaving. Pyro uses his fire-projection power to fend off the police.
The X-Jet arrives to pick them up, and is targeted by two Air Force F-16 fighter jets. They are hit by a missile, but Magneto saves their jet from crashing. Magneto informs them that Stryker orchestrated the attack on the president to provide rationale to raid Xavier's school in order to steal Cerebro's parts, and plans to connect Xavier to a second Cerebro rebuilt at a secret base. The X-Men decide to team up with Magneto and Mystique to stop Stryker. Jean reads Nightcrawler's mind and determines that Stryker's base is inside the dam at Alkali Lake.
Through his son, Jason, Stryker gains control over Xavier, who is brainwashed to use the second Cerebro to find and kill all mutants. Mystique infiltrates Stryker's base by impersonating Wolverine. Storm and Nightcrawler search for the students. Jean, Magneto, and Mystique are attacked by a brainwashed Cyclops while trying to rescue Xavier, and cause damage to the generators that keep the dam from collapsing in the process. The force of Jean's telekinetic blast clashing with Cyclops' optic blast awakens him from his brainwashing, but cracks the dam. Wolverine finds Stryker in an adamantium smelting room, where he recovers some of his memory. Wolverine fights and kills Yuriko, then finds Stryker on a landing pad, where Stryker bargains for his life by offering to reveal Wolverine's past. Wolverine refuses, and binds Stryker in chains.
Storm and Nightcrawler find the students, while Magneto and Mystique kill the rest of Stryker's men. Magneto stops Jason and Xavier from using Cerebro to kill mutants. Disguised as Stryker, Mystique uses Jason to convince Xavier to kill all humans instead; she and Magneto, along with new initiate Pyro, use Stryker's helicopter to escape Alkali Lake, after chaining Stryker to concrete rubble. Nightcrawler teleports Storm inside Cerebro, where she creates a snowstorm to break Jason's concentration and free Xavier from his control.
The X-Men flee the base as water engulfs it, and discover that Magneto, Mystique, and Pyro have escaped on the helicopter. Iceman and Rogue arrive with the X-Jet and get everyone on board. The dam bursts, flooding the landscape and killing Stryker. A malfunction aboard the X-Jet prevents it from taking off; Jean sacrifices herself by using a telekinetic wall to shield them from the flood. She activates the X-Jet's primary engines and drops the torrent of water down on herself, which presumably kills her.
The X-Men give the President Stryker's files, and Xavier warns him that humans and mutants must work together to build peace. Back at the school, Xavier, Cyclops, and Wolverine remember Jean, and Wolverine tells Cyclops that Jean chose Cyclops over him. As the film ends, Xavier states he believes everything will be alright, while a Phoenix-like shape forms beneath Alkali Lake.