The most obvious sign of the success of The Others Guys is in the turnaround. The film begins with a story we might like to see, featuring Samuel L. Jackson and Dwayne Johnson as two ace cops who don’t play by the rules and cause monstrous amounts of destruction wherever they go.

It’s not so much the premise as the casting. Certainly, opening the movie with Johnson clinging to the roof of a speeding SUV while Jackson pursues in a muscle car, with guns blazing all the way, is starting with a bang. It continues along that route to the point of absolute ridiculousness, with Johnson commandeering a double-decker bus and Jackson screaming his own badass variation on the Miranda rights as his car flies toward the perpetrators. Guns, yet again, are blazing all the way.

Highsmith and Danson are the names of these roguish cops, although there is no way to avoid the fact that the joke is in Samuel L. Jackson and Dwayne Johnson playing hotshot detectives. The character names are inconsequential.

The two make the opening sequence funny simply by their appearance in it, although it is to the credit of co-writer/director Adam McKay (who wrote the script with Chris Henchy) that he doesn’t let the casting work solely as the joke. Once the over-the-top introduction concludes, the film plants one foot kind of, sort of in reality. Highsmith and Danson are the be-all and end-all of law enforcement, but their co-workers only pretend to like them to have a chance to share space in the spotlight. When associated with the inferior cops on the force, the two have a defensive outburst. They hold a party to celebrate their most recent takedown and medals, but they make sure to point out it’ll be a cash bar.

Yes, they are awesome, but they are also egotistical jerks.

Enter the eponymous “other guys,” who are relegated to doing Highsmith and Danson’s paperwork because they miss out on the dispatch calls for shootouts, car chases, drug busts, and robberies involving a wrecking ball. They are Gamble and Hoitz, played by Will Ferrell and Mark Wahlberg, again in the sort of roles in which the aptness of the casting is a major part of the joke. Gamble (Ferrell) is an anally retentive paper-pusher, and Hoitz (Wahlberg) is a hot-headed attention-seeker.

Gamble and Hoitz do not make a traditional straitlaced-professional/comedy-sidekick dichotomy; each is both straight man and comic relief to himself. Ferrell and Wahlberg don’t try to play the material for laughs and, as a result, earn them.

The plot, as it is, concerns Gamble and Hoitz trying to make a name for their partnership on the force. Hoitz wants to go after the major cases, although Gamble has only fired a gun once (in the office, as the butt of a practical joke). Gamble, a forensic accountant, believes entrepreneur David Ershon (Steve Coogan) is a criminal. Gamble’s evidence: Ershon has stiffed the city on payments for scaffolding permits.

The jokes, one-liners, and improvised non sequiturs come one after the other throughout the film, and the very large majority of them work — some worthy of a healthy guffaw. McKay and Henchy know which jokes to call back to, including a recurring “soup kitchen” for a group of homeless men (there’s no food involved, only the privacy of deserted vehicles), the incident in Hoitz’ past that earned him the nickname the “Yankee Clipper,” and Gamble’s college days when he called himself “Gator” and earned money taking a percentage of profits from setting up dates for women (although he swears he wasn’t a pimp).

There are also a few standout supporting players. Eva Mendes is Gamble’s “cute-not-hot” (his words) wife, one in a string of women who finds — to Hoitz’ disbelief — Gamble attractive (and who turns Hoitz into a bumbling fool). Michael Keaton appears as the guys’ captain, who holds a second job as a retail manager to pay for his son’s tuition. Coogan has some early laughs as a firm believer in the free market, especially when it allows him to cheat other people into playing his multi-billion-dollar debts. Coogan’s Ershon adds a heavy layer of cynicism to the proceedings, culminating in a visit to the Securities and Exchange Commission, who are the best at stopping people like Ershon (except for Gamble’s long list of times they didn’t), and continuing through the end credits (which run over animated graphs of the effects of reckless capitalism).

While it suffers from inevitable lag during third-act plot reveals and generic action sequences, The Other Guys is a tight comedy that skillfully maneuvers from the extremes of specific parody (discussing the physics of movie explosions) to general absurdity (Gamble and his wife exchanging naughty dialogue through her grandmother) and many points in between.

Mark Dujsik is a member of the Chicago Film Critics Association and the Online Film Critics Society. For more of his reviews, visit his website.