So here’s Michael “Transformers” Bay directing the guy who played the likable and goofy Jim on “The Office” in a gritty film based on the attack on the U.S. consulate in Benghazi, and though that might sound like the premise for an article in the Onion or a satirical trailer on “Funny or Die,” this is a solid action thriller with well-choreographed battle sequences and strong work from the ensemble cast.

Of course, this being a Michael Bay movie, there are moments when deadly battles are given the glorious, slow-motion treatment and lit like fireworks displays, and if you think Bay’s camera will linger on the American flag more than once, well, you’ve seen your share of Michael Bay movies, haven’t you?

Sporting a full beard and layers of muscle, John Krasinski is nearly unrecognizable as Jack Silva, the newest member of a small team of CIA contractors in Benghazi acting as security for a CIA outpost manned by about 30 operatives tracking the movement of weapons in the post-Gadhafi Libya, where the situation is unstable on the best of days. (The name has been changed, but Krasinski’s character and the rest of the team are based on real-life former military men who fought the terrorists who stormed the American diplomatic compound on Sept. 11 and 12 in 2012.)

Jack is married with two little girls, with a third child on the way. (A scene in which Jack inadvertently learns the news while on a phone call with his wife, who is at a drive-through at a McDonald’s back home, isn’t exactly subtle, but it’s effective.)

In fact, each of the six Annex Security Team members is a father. When they’re not risking their lives in the Middle East for country and cash, they work in insurance or selling homes. Some are in Benghazi because they need the money; others are there because they are soldiers through and through, and as one of them puts it, warriors aren’t meant to retire.

Although there are a few tense encounters right from the get-go, with the Americans trying to figure out who’s friendly and who’s against them, Bay and screenwriter Chuck Hogan take a comfortable amount of time establishing characters and giving us a lay of the land, geographically and politically, before we’re plunged into the nightmare of the continued assaults on the U.S. Diplomatic Compound.

James Badge Dale delivers charismatic work as Tyrone “Rone” Woods, Jack’s best friend and the leader of the team. Max Martini, Pablo Schreiber, Dominic Fumusa and David Denman (who played Roy, Jim’s rival for Pam’s affections, on “The Office”) are all believable as former Navy SEALs and Marines who comport themselves with great swagger and bravado — and back it up when the stuff hits the fan.

David Costabile is Bob, who heads the CIA team. Of course Bob is a fussy, arrogant desk commander who has nothing but disdain for what he calls “security guards,” and of course Bob is indecisive and weak when gunmen storm the compound. You need a Bob in a movie like this.

“13 Hours” isn’t interested in introducing us to any of the terrorists who attack the compound or in explaining their motivation other than they want to kill Americans.

When the first wave of attacks hits the building (often and unofficially referred to as the consulate) occupied by Ambassador Christopher Stevens (a well-cast Matt Letscher), the Annex men are about a mile down the road, at their assigned post protecting the CIA operation.

They have no authority to join the battle, even though the small unit assigned to protect the ambassador is hopelessly outmanned. In fact they’re told to stand down, while Bob makes some phone calls to determine when and how the U.S. can send reinforcements.

Even though they’re private contractors, the team members are American soldiers to the core, and they refuse to stand by while countrymen are under attack. From that point forward, “13 Hours” is one extended battle sequence after another, with the consulate going up in flames, harrowing chase sequences and multiple shootout scenes back at the CIA compound. The body count soars, with dozens upon dozens of Libyan gunmen taken out by the Americans, who suffer casualties of their own.

There’s very little politicking in “13 Hours,” other than a moment when one of the Americans notes the mortar attack had to have been planned weeks in advance. This was no spontaneous demonstration gone horribly wrong, as we were initially told at the time.

And of course there’s an unspoken but quite loud indictment of the Obama administration and in particularly then-Secretary of State Hillary Clinton. Not only did we not see this coming, but for 13 long hours, it was up to a half-dozen civilians to protect American lives. Highly trained former military, to be sure, but civilians nonetheless.

This is no “Zero Dark Thirty” or “The Hurt Locker.” Lacking in nuance and occasionally plagued by corny dialogue, “13 Hours” is nonetheless a well-photographed, visceral action film, and a sincere and fitting tribute to those secret soldiers.

[s3r star=3/4]

Paramount Pictures presents a film directed by Michael Bay and written by Chuck Hogan. Running time: 144 minutes. Rated R (for strong combat violence throughout, bloody images, and language). Opens Friday at local theaters.