At a high school graduation party, a punk rocker played by Matt Damon sings a song called “Scotty Doesn’t Know,” about how Scott is unaware that he, the singer, is sleeping with his, Scott’s, girlfriend. The joke is that both Scott and the girlfriend are there at the party, Scott standing forlornly amidst a crowd of head-bopping revelers, the girlfriend making out with the singer onstage.

“Scotty Doesn’t Know” re-emerges several times in “Eurotrip,” each time funnier than the last. It’s a rare example of a teen-movie running gag that’s actually funny, and it’s in good company in this exuberant, unabashedly raunchy tale about the magical powers of hormones and alcohol.

“Eurotrip’s” ancestors include “Porky’s” and “Risky Business,” with the “American Pie” films being its most recent relatives, at least among those that were artistically successful.

Yes, I said artistically. There’s an art — I wouldn’t call it a fine art, but an art nonetheless — to tapping into an adolescent audience’s psyche and knowing what will make them laugh. Perhaps surprisingly, it’s the same things that make grownups laugh: carefully contrived situations, snappy dialogue and a lighthearted attitude. The only difference for a teen film is that the situations, dialogue and attitude all center around boobs. But the principles are the same.

“Eurotrip,” written by Jeff Schaffer (who also directed), Alec Berg and David Mandel — the trio behind “The Cat in the Hat,” unfortunately — is about Scott’s (Scott Mechlowicz) last-minute trip to Europe to meet his hot German pen pal, Mieke (Jessica Boehrs). He is suddenly interested in her romantically because he’s been dumped by the aforementioned cheating girlfriend, and because he’s only just learned that Mieke is not a guy. (He’s been pronouncing it “Mike” all this time.) Scott is accompanied to Europe by Cooper (Jacob Pitts), playing the role of the oversexed, carefree best friend.

They can’t get cheap tickets to Berlin, so they settle for London, where they befriend a brutish soccer team and eventually wind up in Paris. (The sight of the team bus indignantly driving the wrong way down every French street, swearing viciously at all who dare oppose them, is supremely funny.) Here they meet up with their old high school friends Jenny (Michelle Trachtenberg) and Jamie (Travis Wester), who are twins. Jenny is considered “one of the guys” by everyone, and Jamie is an uptight control freak who has planned their European vacation down to the minutest, boringest detail. Still, the four are friends, and though it takes some work to convince Jamie to loosen his grip on the itinerary, they set off for Berlin, by way of several other destinations.

Then it’s one set piece after another, some funnier than others, but none completely useless or grating. They visit a nude beach, deal with an aggressively affectionate Italian train passenger (Fred Armisen, from “SNL”), partake of the debauchery that is Amsterdam, and accidentally elect a new pope at the Vatican (don’t ask).

Though nothing really says “breakout performance,” the mostly unknown cast acquits itself winningly and with comedic skill. It helps that the comedy, while outrageous, vulgar, crude and sexual, is not of the gross-out variety. The focus is on sex and drinking, not defecation and vomiting.

Four of the film’s eight credited producers also worked on “Old School,” another film that was raucously funny but not disgusting. I suspect audiences who enjoyed it will enjoy “Eurotrip,” too, whether they are adolescents or merely think like them.

B (1 hr., 32 min.; R, abundant harsh profanity, quite a lot nudity, most of it non-sexual.)