With a whoosh, the X-Men go forward to the past, or possibly sideways to an alternative present. This headspinning and chaotic time-travel adventure is written by Jane Goldman, Simon Kinberg and Matthew Vaughn for director Bryan Singer: a funky, surreal experiment in counter-factuals and variant myths. It channels Watchmen, The Terminator, The Matrix, Life on Mars and Independence Day. At its best, it's delirious, crazy fun with splashes of passion and romance; at its worst, it gets muddled (the way time-travel films will always tend to) and becalmed in its own fanboy portentousness.

We begin in a dark future. The war between the non-mutants and the mutants has resulted in devastation all over the world. No one, it seems, is the true winner. Some holdout mutants appear to be battling a rearguard guerrilla action against terrifying new soldier-robots called Sentinels. They are physically at a disadvantage but have the ability to escape through portals in the space-time continuum – they can scoot back in time to warn themselves when and where a Sentinel attack is on the way.

Sorry, your browser is unable to play this video.

It is upon this grim scene that Professor Xavier (Patrick Stewart), Magneto (Ian McKellen) and Wolverine (Hugh Jackman) make an almost Shakespearian entrance, like an exiled king and his retinue. Xavier is excited by the potential of time-travel to rescue their destinies. The new plan is that Wolverine will go back many decades to 1973, but there will be no ironic retro kidding around. This is when Raven (Jennifer Lawrence), or now rather Mystique, made her fateful attempt to assassinate anti-mutant scientist Dr Trask (Peter Dinklage) at the Paris peace conference. The way things turned out, she was captured and through some hideous scientific means her metamorphic properties were decanted to create the Sentinels. If only Mystique can be stopped, then none of this will happen.

What Wolverine must do is go back in time – or rather, his mind must go back, in a sort of Inception-style inner universe, while he twitches on a bed covered with wires – to persuade Magneto and Xavier's younger selves to join him in this exotic quest. The problem is that he will be a stranger to the younger generation, who are played by James McAvoy and Michael Fassbender. The further complicating factors are that Xavier is at this stage able to walk, with medication that however strips his mental powers, and the metal-controlling Magneto is incarcerated in an ultra-secure unit below the Pentagon, in Loki-cum-Lecter seclusion, suspected of having been behind the Kennedy assassination, with its well-known swerving bullet. Wolverine and Xavier have to spring Magneto, and this opens old wounds. It reawakens their angry debate about how mutants should comport themselves, and their feelings for the beautiful Mystique herself.

Perhaps inevitably, it is in the film's opening act where almost all the fun is to be had. Wolverine firstly recruits Beast (Nicholas Hoult) and Quicksilver (Evan Peters) to help him bust into the Pentagon. Quicksilver's infinitely fast moves effectively trump every other power and superpower; it is a slight bafflement, in fact, that Quicksilver himself does not rule the world, or at least appear in much more of the film. There is a glorious "bullet-time" scene during a shoot-out in which Quicksilver ambles around, catching the bullets as they float towards the cowering, freeze-framed Magneto and Xavier – and all to Jim Croce's yearning song If I Could Save Time in a Bottle.

Fassbender's Magneto is curt, cool, duplicitous – an elegant foil to Xavier and his angry self-pity. Set against them is Lawrence's Mystique, who is always required to disport herself in her blue body-hugging quasi-nudity. (As Spinal Tap's Nigel Tufnel might have commented: "What's wrong with being sexy?") As for Jackman's Wolverine, he is as robust and unassuming as ever, though I feel he is always in danger of being upstaged by the other, more cerebral and self-aware characters.

The action flashes eagerly around – to Vietnam, Paris, to that post-apocalyptic wasteland from which Wolverine makes his blast to the past. And, of course, there's Washington DC, where the mutants are to encounter the president, Richard Nixon (Mark Camacho), in a truly spectacular setting. Finally, the X-Men extricate themselves from incoherence – more or less – with the help of a newspaper front page that explains to the audience how exactly a reasonably happy ending has supposedly been achieved. It was a dizzying but enjoyable ride.