‘Hamlet 2” is a shambles of a movie hurled from the screen with ten thousand seams showing. Tonally, it’s all over the map, and the plot goes nowhere we haven’t seen before.

But wow, when “Hamlet 2” gets on a roll, it leaves you delirious (the friend I went with said he hurt his stomach from laughing so hard), and its faults are easy to ignore when you’re busy cracking up. Since the movie is really just a vehicle to introduce Americans to Steve Coogan, we can forgive it all the more, because he’s a brilliant comedic talent. Coogan is a household name in his native Britain, but his performance in “Hamlet 2” should cement his stateside reputation.

The plot revolves around Dana Marschz (Coogan), the saddest sad sack around. Marschz is almost too pathetic: He’s a talentless nobody with severe boundary issues who rides to work on roller skates he can’t seem to stay upright on. After years of fruitless attempts at an acting career — the farthest he seems to have gotten is playing “Guy with Herpes” in a commercial — he’s settled down to teach drama at a high school in Tuscon (presented here as the seventh layer of Hell). With only two students and a repertoire of low-grade adaptations of hit movies, the drama class isn’t exactly top-notch. But life, as it tends to do in films like this, takes a sudden turn when all electives but drama are cut from the school’s curriculum, filling Marschz’s class with what one of his students calls “ethnics” and what we’d call “Latinos.”

Most of the humor in “Hamlet 2” derives from its weirdness and its propensity for slapstick, but it’s nice to see that its racial politics are the cleverest part of the movie. The vomit-inducing “Dangerous Minds” educational trope is thankfully turned on its head, as the kids from the streets teach and inspire the most idiotic white guy in Tuscon.

Budget cuts soon threaten to close the drama department completely and, in desperation, Marschz turns to the play he’s been nursing for years — a sequel to Shakespeare’s “Hamlet” featuring time travel, singing and an orgy with Hillary Clinton, among other things.

“Hamlet 2” is generous to its actors, and several of them shine, including Catherine Keener as Marschz’s put-upon, alcoholic wife. But the movie belongs completely to the shameless and wonderful Coogan. Marschz fits right into his oeuvre, populated as it is by delusional, awkward losers. In fact, he might be Coogan’s most awkward and delusional character ever. Crushed by failure and tormented by a long-lost father, Marschz practically begs for love like a dog left on the street, even as he casts himself in the role of a fearless and inspirational leader. He’s almost sociopathic in his inability to connect. The irony, of course, is that he winds up triumphant by the movie’s end, his severe traumas turned into something glorious.

By its very nature, “Hamlet 2” walks a precariously thin line, and there are times when it steps on the wrong side. It veers wildly from over-the-top parody of parody to sharply drawn satire to broad slapstick. Some random quirks are milked to exhaustion (did we have to see Marschz take a tumble on his roller skates over and over again?) while uninteresting subplots threaten our attention spans (as usual, they involve that perennial character, the Wife Who Is Given Nothing To Do In The Movie). We also get a bit of what we’ll call Napoleon Dynamite Syndrome, featuring an assortment of oddball folk with stilted speech patterns. This all makes for a very chaotic experience.

But so winning is the cast and so cheerful the filmmaking in “Hamlet 2,” who cares about consistency? Ultimately, the chaos culminates in a mind-blowing performance of the titular play. And, really, where else are you going to get a full-blown production number called “Rock Me Sexy Jesus,” with the tune cribbed from “Little Shop Of Horrors” and the lyrics paying tribute to a certain messiah with a “hot swimmer’s bod”? Or, for that matter, a climactic fight scene with lightsabers and the Tuscon Gay Men’s Chorus singing Elton John in the rafters?