The first shots exploded around 9:40 p.m.

On Sept. 11, 2012, a group of local fighters, AK-47s in hand, burst through the fortified front gate of a US outpost in Benghazi, Libya.

One very long night later, the diplomatic compound was engulfed in flames and a covert CIA base a mile away lay in ruins, partially reduced to rubble by mortar fire. Four Americans were dead, including Ambassador Christopher Stevens and two CIA members.

What happened in between is covered in “13 Hours: The Secret Soldiers of Benghazi,” a new film from “Transformers” director Michael Bay in theaters Friday.

It focuses on a team of six military contractors who happened to be stationed at the CIA base when the fighting broke out. They chose to join the battle, spending more than half a day repelling attackers.

“We wanted it [the film] apolitical….it was a story of heroism. That was getting lost in the politics of it all.”

The movie is based on the book “13 Hours: The Inside Account of What Really Happened in Benghazi” by Mitchell Zuckoff and that team of operatives.

“That’s the reason we did the movie,” one of the contractors, ex Marine Mark Geist, tells The Post. “No one has talked about those 13 hours and what happened.”

Not that certain people haven’t been trying to find out. The incident has become one of the most highly politicized events in modern US history. Who was to blame for the debacle? Republicans have been hellbent on pinning it on then-Secretary of State Hillary Clinton.

Congress has launched seven investigations, recorded dozens of hours of testimony and generated thousands of pages of documents.

But the men who were there say the movie has nothing to do with Washington, DC, or presidential campaigns.

“We wanted it apolitical,” Kris “Tanto” Paronto, a former Army Ranger and one of the Benghazi six, tells The Post. “From the time we got the call to the time the last [CIA Global Response Staff member] got out of Benghazi 13 hours later, it was a story of heroism. That was getting lost in the politics of it all.”

“For all of us, it was that the four [deceased] guys got honored in the way they should,” operative and ex Marine Sergeant John “Tig” Tiegen, tells The Post.

“Politicians hijacked it. The right use it, the left use it, and the true story got lost,” Paronto says. “The truth isn’t political. Now, the truth may affect political aspirations, but hey, sorry, that’s how it goes. We want people to know the true story, and if they want to use it as a determination of candidates, we can’t stop that. But we’re not going to get up there and say, ‘You should pick this person.’ ”

The day began with signs of trouble.

At 6:43 a.m., a car bearing Libyan police markings filled with three men pulled up to the diplomatic outpost. One man got out, climbed to the second floor of a restaurant overlooking the outpost and began taking photos. By the time security was alerted, the men and the car had vanished.

A mile down the road at the Annex — the walled, 2-acre, multibuilding compound that served as a base of operations for US covert intelligence services — it was business as usual for the soldiers.

Tiegen spent the morning accompanying the station chief, known only as “Bob,” on meetings with Libyan officials. Tiegen also checked in at the outpost, where Stevens had just arrived the day before.

Geist exercised and played video games. Paronto worked on computer-mapping software, then watched the Liam Neeson movie “Wrath of the Titans.”

As the men prepared to turn in for the night, down the road at the outpost a Toyota pickup bearing police insignia pulled in front of the gate and idled there for 40 minutes.

Just as it drove off, shots rang out and there was an explosion. Several dozen heavily armed men poured through the front gate. The Libyans, who had been guarding it, quickly melted away.

The seven Americans inside quickly barricaded themselves in locked rooms. A distress call was sent to the embassy in Tripoli and to Washington. The attackers dumped diesel fuel around the grounds and set it alight.

Over at the Annex, the security team was told to grab their gear and assemble. They loaded guns and body armor into a waiting armored car as they watched flames rise from the nearby outpost.

A lot of politicians don’t realize that we were all in the military and we know a lot of the military guys, and they tell us things.

Before they could leave, however, the men were inexplicably told to “stand down” by Bob, the station chief. He preferred to let a friendly Libyan militia respond. (A congressional inquiry later concluded there was no evidence a “stand down” order was issued, but the “13 Hours” men say it happened.)

As they helplessly waited, a call from the outpost came over the radio: “If you don’t get here soon, we’re all going to die.” The group took matters into its own hands. The three contractors were also joined by ex-SEALs Tyrone Woods and “Jack Silva” (played by “The Office alum John Krasinki in the film) and former Marine “Dave Benton,” both pseudonymous names because their real identities have not been revealed.

The men made the journey to the outpost by car, then approached on foot. They arrived to find Stevens missing and officer Sean Smith dead from smoke inhalation.

As the team prepared to return to the Annex, with Smith’s body in the trunk of their car, the compound came under fire again. A vicious counterattack by the group of Libyans began around 11 p.m.

The team fought back. Tiegen climbed to a rooftop and killed a man aiming a rocket-propelled grenade launcher at one of the buildings. Minutes later, the operators and surviving outpost personnel were packed into two cars, driving the dangerous streets back to the Annex.

Around 12:30 a.m., cars full of enemy fighters began massing outside the Annex walls. A firefight began, and 10 minutes later, the first wave was repelled. More attacks followed before dawn broke. Suddenly, mortars rained down, landing atop a building and killing Woods and Glen Doherty, a former SEAL who’d arrived in the night from Tripoli.

He would be about the only outside assistance the Annex would get. Despite repeated calls for air support, none ever came. The Annex staff was ultimately evacuated to the airport and out of the country with the help of a Libyan militia. (Stevens was found by Libyans inside the outpost nearly dead from smoke inhalation. He later passed away.)

“This wasn’t the worst [firefight of my life], but it was the longest,” Paronto says. “The only difference with this one was that we were left behind. That’s just the truth. No support came. Period.”

“There are pilots that come up to us and say, ‘Sorry, dude. We were ready to go,’ ” Geist says.

The movie suggests that F-16s or gunships could have been scrambled from Europe, though a congressional committee determined none were available to make it in time.

The men who were there disagree.

“A lot of politicians don’t realize that we were all in the military and we know a lot of the military guys, and they tell us things,” Tiegen says. “One pilot said to us that [the government] was afraid of another ‘Black Hawk Down’ scenario.”

Though the men now suffer from post-traumatic stress (they refuse to term it a “disorder”), they say the movie makes them miss their other life and want to return to Libya.

“It’s enjoyable,” Tiegen says. “We’re over there whacking terrorists so they can’t come over here.”

“You’re your best person when you’re over [there]. You’re willing to give your life for someone,” Paronto says. “And you miss the brotherhood. Everything’s dull when you get back to the States.”