In the future, robots known as Sentinels are exterminating mutants and their human allies. A band of mutants evades the Sentinels with the help of Kitty Pryde, who has the ability to send a person's consciousness into the past. Pryde's group convenes with Storm, Wolverine, Professor Charles Xavier, and Erik Lehnsherr at a monastery in China. Kitty sends Logan's (Wolverine's) consciousness 50 years back in time to 1973 to prevent Mystique from assassinating Bolivar Trask, creator of the Sentinels. Following the assassination, Mystique was captured, and her DNA was used by Trask's company to improve the Sentinels, whose ability to adapt to any mutant power makes them almost invincible. Charles and Erik advise Logan to find both of their younger selves for help.
At the X-Mansion in 1973, Logan encounters Charles and Hank McCoy. Xavier's Institute for Gifted Youngsters has closed after most of the teachers and students were drafted to the Vietnam War. Charles, a broken man, has been overusing a serum that allows him to walk but suppresses his telepathy. Logan explains his mission and persuades Charles to help free Erik from a prison cell beneath the Pentagon, where he is being held for allegedly assassinating President John F. Kennedy. They rescue Erik with the help of Peter Maximoff, a mutant with super speed.
In Washington D.C., Trask unsuccessfully tries to sway Congress to gain support for his Sentinel program. Meanwhile, in Saigon, Mystique prevents William Stryker from appropriating a group of mutant G.I.s for Trask's research. Mystique investigates Trask's office and discovers he has been capturing mutants to use for his experiments. Charles, Erik, Hank, and Logan fly to Paris to intercept Mystique, who is impersonating a North Vietnamese general to infiltrate the Paris Peace Accords. There, Trask attempts to sell his Sentinel technology to Communist nations. Charles' group arrives as Mystique is about to kill Trask. Erik tries to kill Mystique to ensure her DNA cannot be used for the Sentinels, but she jumps from a window. The fight spills onto the street in view of the public, allowing Erik and Mystique to escape.
Trask is saved, but the world is horrified by the existence of mutants. President Richard Nixon approves Trask's Sentinel program and arranges an unveiling ceremony. Trask's scientists recover Mystique's blood from the street. Meanwhile, Erik—who has recovered his telepathy-blocking helmet—intercepts the prototype Sentinels in transit and laces their polymer-based frames with steel, allowing him to control them. At the mansion, Charles stops taking his serum and slowly regains his mental powers, while losing the ability to walk. Through Logan, Charles speaks to his future self and is inspired to work for peace between humans and mutants once again. He uses Cerebro to track Mystique, who is heading to Washington D.C.
As Charles, Logan, and Hank search for Mystique, Nixon unveils the Sentinel prototypes at the White House. Erik commandeers the Sentinels and attacks the crowd, then sets the Robert F. Kennedy Memorial Stadium around the White House as a barricade. Nixon and Trask, accompanied by the Cabinet, Secret Service officers, and Mystique (disguised as a Secret Service member), are taken to a safe room. Logan and Hank try to stop Erik, but he pits a Sentinel against them and then throws Logan into the Potomac River. In the future, the X-Men make their final stand as a large army of Sentinels attack the monastery. In 1973, Erik pulls the safe room from the White House and prepares to kill Nixon and his Cabinet. Mystique, who is disguised as Nixon, incapacitates Erik with a plastic gun. Charles persuades Mystique to spare Trask and allows her and Erik to flee. Mystique's actions are seen as a mutant saving the President, leading to the cancellation of the Sentinel program. Trask is arrested for trying to sell American military secrets.
Logan wakes up in the future to find Bobby Drake, Rogue, Peter Rasputin, Kitty, Hank, Storm, Jean Grey, Scott Summers, and Charles are all alive. In 1973, Mystique impersonates Stryker and takes custody of Logan.
In a post-credits scene, a crowd chants to En Sabah Nur, who is using telekinesis to build pyramids as four horsemen watch from nearby.