When last we visited the X-Men, Marvel’s mutant franchise was finding its bearings after a couple of bad-to-wobbly entries. Begun in confident fashion, the story of the shunned superhero subculture veered astray before righting itself with the retro prequel “X-Men: First Class.”

That 1960s-set prologue featured fresh, energetic talents playing youthful versions of established characters. The Bond-inspired rouser gave us James McAvoy subbing for Patrick Stewart as benign telepath Professor X, Jennifer Lawrence replacing Rebecca Romijn as blue-skinned shape-shifter Mystique, and an appropriately magnetic Michael Fassbender stepping in for Ian McKellen’s destructive Magneto.

Now comes another blast from the past. “X-Men: Days of Future Past” is a sequel to the prequel that unites the new and original casts in a time-traveling extravaganza. It ranks as one of the best. Director Bryan Singer, who originated the series in 2000, returns to the helm, building on the rejuvenated energy of the previous installment while pushing the scenario to ambitious new extremes.

The story begins in doom-laden end times. Invincible robots patrol a dead future Earth, about to exterminate the final few gifted mutants. Weary Professor X (Stewart) and Magneto (McKellen) are trapped in a deserted Chinese monastery with Hugh Jackman’s bellicose brawler Wolverine and a few others. The only way to prevent the mechanoid killers from completing their mission is to send Wolverine back through time to stop the war before it begins.

Well, yeah, it sounds easy. But following the events of the previous film, young Professor X is a powerless, drug-addicted recluse. Magneto, at this point his mortal enemy, is in an impenetrable lockup for a political assassination. Mystique has gone rogue on a vendetta of vengeance. And the character who must bring them together is the least diplomatic personality in the Marvel universe.

That’s a lot of plates to keep spinning, but Singer, who made his breakthrough with the similarly tricky “The Usual Suspects,” never falters. There’s a sense of genuine peril in the dystopian future scenes, and breathless action beats that elevate Lawrence from eye candy to game changer. There’s a canny grasp of Watergate-era Washington chicanery in the 1973 scenes, and the film’s humor never descends to broad satire. Waterbeds, Pong, boss-looking muscle cars and “Star Trek” all get affectionate nods. Pre-PC technology, not so much.

The film is visually exciting, aping the look of period camerawork effectively in several 1970s scenes. The actors aren’t overwhelmed by effects for the most part. The troubled, profane McAvoy is outstanding, especially in a sequence when his older and younger selves have a meeting of the minds. There’s so much going on in this rich story that some of the excellent cast is underused. I’d have liked to see more from McKellen and Peter Dinklage as the technocrat lobbying Congress to fund his mutant-killer machines.

I’m thrilled, however, that the film found the time to introduce a terrific new mutant character. Evan Peters makes a grand entrance as super-swift teen Quicksilver, who’s crucial to breaking Magneto out of prison. A smug nuisance well on his way to juvenile delinquency, he’s part Road Runner, part wiseguy Bugs Bunny. Running rings around the guards, he flicks away their bullets, swipes their hats and gives one a world-class wedgie. Like Hulk in “The Avengers,” he’s the movie’s breakout surprise. Let’s hope this speed demon is part of the team working on the next sequel.