At the White House, the 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. The Professor discovers that a covert government operative, William Stryker, has been extracting information from Magneto. 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 any 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. She also learns of plans for 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 Boston Police Department arrive just as the group is leaving. Pyro uses his fire-projection power to fend off the police, and Rogue stops him when he starts attacking savagely.
The X-Jet arrives to pick them up, and is targeted by two Air Force fighter jets. It is hit by a missile but does not crash due to the sudden intervention of Magneto. The X-Men reluctantly team up with Magneto and Mystique to stop Stryker. At their camp, Magneto learns that Stryker orchestrated the attack on the president to provide rationale to raid Xavier's school and use an injectable drug to control the mutant students. Jean reads Nightcrawler's mind and determines that Stryker's base is inside the dam at Alkali Lake, where he plans to kill all mutants with a second Cerebro.
Through his son, Jason, Stryker gains control over Xavier, who is brainwashed to use Cerebro to find and kill all mutants. Mystique infiltrates Stryker's base by impersonating Wolverine. Storm and Nightcrawler search for the kidnapped students. Jean, Magneto, and Mystique are attacked by a brainwashed Cyclops while trying to rescue Xavier, and in the process cause damage to the generators that keep the dam from collapsing. The force of Jean's telekinetic blast clashing with Cyclops' optic blast awakens him from his brainwashing, but also cracks the dam. Wolverine finds Stryker in an adamantium smelting room, where he recovers some of his memory. Wolverine fights and defeats Yuriko, then finds Stryker on a landing pad, where Stryker bargains for his life by offering to reveal Wolverine's past. Wolverine refuses, and instead binds Stryker in chains.
Storm and Nightcrawler find the students. Magneto and Mystique kill the rest of Stryker's men, and Magneto stops Jason and Xavier before Cerebro kills any mutants. Disguised as Stryker, Mystique uses Jason to convince Xavier to kill all the humans in the world 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, freeing Xavier from his illusion.
The X-Men flee the base as water engulfs it, only to 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 leaving the jet and creating a telekinetic wall as a shield against the flood. She activates the X-Jet's primary engines before releasing the torrent of water down on herself, presumably killing her.
The X-Men give the President files from Stryker's private offices, 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, a Phoenix-like shape forms beneath Alkali lake.