Mark Wahlberg and director Baltasar Kormakur came a-cropper with their first collaboration, the flaccid “Contraband,” but they strike paydirt with this follow-up, a buddy-cop action flick with a ludicrously convoluted plot but plenty of energy and good star chemistry. So long as you’re willing to buy into the premise that everyone and everything in America is corrupt—a notion that many viewers will quickly nod in agreement with nowadays—“2 Guns” delivers a barrage of firepower that’s hard to resist.

The picture opens with a scene at a diner in little Tres Cruces, New Mexico, that immediately establishes the rapport between amusingly solemn Bobby Trench (Denzel Washington) and garrulous goofball Stig Stigman (Wahlberg), a pair of crooks preparing to rob a bank across the street in an elaborate heist that involves jailing the local cops and setting the diner ablaze. After this setup, the picture backtracks to explain how the duo decided to empty a vault filled with proceeds from the drug operations of Mexican cartel overlord Papi Greco (Edward James Olmos), with whom they’ve established a business relationship. It’s also revealed that the guys aren’t the crooks they seem to be: Trench is an undercover DEA agent and Stig an operative for Naval Intelligence. Of course, each is ignorant of the other’s real identity.

The scheme goes off without a hitch—almost. It turns out that the vault contains not the three million the boys expected, but about forty million more than that. Trench and Stigman take it all, but facing off against one another afterward Stig shoots Trench—not fatally, of course—and delivers the cash to his superior Quince (James Marsden), who answers to their base commander, Admiral Tuwey (Fred Ward). Meanwhile Trench makes it back to his handler—and on-and-off girlfriend—Deb (Paula Patton), and their boss Jessup (Robert Lee Burke).

What neither man knows is that neither side of the equation is playing a straightforward game. And soon the guys are in serious trouble not only with their own organizations, but with Papa Greco and a mysterious operative named Earl (Bill Paxton), who may exude a down-home, aw-shucks Texas vibe but is more steely and ruthless than anybody else in the mix. All of this leads to an avalanche of action scenes—gunfights, car chases, kidnappings, torture interludes, explosions, and even—if you can believe it—a cattle stampede. The latter is just one part of a big finale that involves nearly all the characters and one razzle-dazzle stunt after another, including a totally gratuitous helicopter crash (along with plenty of bodies). It all feels like one of Walter Hill’s wackier macho efforts from the eighties.

“2 Guns” is obviously a giddily over-the-top affair that no one could take remotely seriously, but it works for a couple of reasons. One is that scripter Blake Masters, Kormakur and editor Michael Tronick manage to keep the twists and turns of the plot comprehensible, no matter how ridiculous they become. The other is that Washington and Wahlberg prove well-suited to one another. Though unlikely partners, they manage to express a sense of camaraderie beyond the machinations of the screenplay. And while Wahlberg, with his machine-gun string of nutty observations, gets the lion’s share of the funny lines, Washington is no slouch in delivering his humorous dialogue either. It’s at the moments that the narrative goes into serious mode (as with the stuff concerning Deb as damsel in distress) that things threaten to go off the rails. Happily those moments are few; there’s no deep subtext here to plumb.

The rest of the cast seems to be having a good time, too. Paxton takes pride of place with his drawling badass routine, but Olmos isn’t far behind. Patton and Marsden aren’t given anywhere near the same opportunity to shine, but Ward makes the most of what amounts to a cameo. Technically all is well, with expert stuntwork and effects and sterling widescreen cinematography by Oliver Wood, who uses the locations to superb effect.

“2 Guns” pays its respects to an obvious inspiration, Don Siegel’s 1973 “Charley Varrick,” and its script by Howard Rodman and Dean Reisner from John Reese’s “The Looters,” upfront in the bank heist sequences That’s probably cheaper than an actual credit, but at least it’s something for movie buffs to savor. Speaking of which, that Walter Matthau picture is well worth searching out if you haven’t seen it.