The terrorists threw everything they had at the U.S. consulate: a truck bomb, grenades, rockets, mortars and 15 black-clad attackers armed with AK-47s, including one fighter strapped with a suicide vest trying to blow out the back door.

It could have turned out badly — another Benghazi — but it wasn’t scripted that way. This time, all 20 personnel inside the five-story consulate would survive. None of the attackers did, mowed down by agents from the State Department’s Diplomatic Security Service, who responded crisply with automatic weapons spewing fiery, loud bursts in the early-morning haze.

The terrorists were, in fact, excited young Marines fresh out of infantry school, role-players in a rapid-fire training exercise in a mock town built for war games on a Virginia military base. Replete with Hollywood-style explosions and actors chanting anti-American slogans in Arabic, it was the culmination of an intensive training program that owes its existence to the fatal 2012 attacks by Islamic militants on U.S. installations in Benghazi, Libya.

A review board cited “grossly inadequate” security, a lack of Diplomatic Security agents and poorly skilled local guards as factors in the rout at Benghazi that killed four Americans, including the U.S. ambassador. In response, then-secretary of state Hillary Rodham Clinton created a high-threat directorate within the security branch so U.S. outposts in dangerous places “get the attention they need,” she said.

Participants playing the roles of anti-American demonstrators burn an effigy outside a fake U.S. consulate in the make-believe town of Erehwon, “nowhere” spelled backwards, during the capstone of a Bureau of Diplomatic Security training course in May. (Jahi Chikwendiu/The Washington Post)

During an exercise, diplomatic security agents escort a make-believe consular general from a building under attack in Erehwon. Theron Bunnell, right, a high-threat program trainer, oversees the process. (Jahi Chikwendiu/The Washington Post)

Republicans have continued to pound on the Obama administration’s response to the incident, while Democrats see only political posturing. But none of it particularly registers in the fictional nation of Erehwon — “nowhere” spelled backwards — where Diplomatic Security agents since last fall have sweated through motorcade ambushes and helicopter evacuations as part of stepped-up training.

The high-threat course lasts 10 weeks — its duration was doubled after Benghazi — and students are put through their final paces during three-plus days amid Erehwon’s pine trees and the occasional flock of wild turkeys. A squad of 16 men completed it last month, the latest of 47 graduates since October. (The State Department asked that the base’s name not be disclosed to maintain the element of surprise for future trainees.)

Two thousand DS agents, as they are known, protect diplomats and U.S. outposts in 160 countries. Many agents undergo DS basic training — including firearms and trauma-care instruction — at a West Virginia facility that includes a racetrack for high-speed driving maneuvers. The so-called capstone event at Erehwon is meant to connect the lessons in order to protect a pretend diplomat and eventually evacuate him as the U.S. mission in Erehwon is abandoned.

After the 2012 attacks in Benghazi, Libya, that resulted in the deaths of U.S. Ambassador J. Christopher Stevens and three other Americans, then-secretary of state Hillary Rodham Clinton ordered initiatives that include an expanded training program for agents heading to high-threat posts. The third class to undergo the training test their skills in a three-day lifelike capstone exercise, complete with AK-47s and car bombs. (Whitney Leaming/The Washington Post)

Along the way, as with military combat exercises, the students deal with exhaustion, casualties who must be carried and a wily, adaptive enemy — in this case, trainers who monitor everything from a state-of-the-art tactical operations center where they shift elements of the scenario to keep the students off guard.

They also use deception: One night the puppet-masters fired “mortars” from one direction so that the group, slogging a mile across a creek in the dark toward a helo-landing zone, would think the enemy was advancing from behind. A version of a BlackHawk helicopter, designed to ferry VIPs, was enlisted to “extract” the DS agents and diplomats, who carried one student on a stretcher.

“It was not easy,” said Alex, a 43-year-old agent who asked that his last name be withheld for security reasons. He and other grimy graduates, who had not showered in days, were trudging back to the pretend consulate for a lengthy after-action critique.

Within an hour or so of repelling the attack, the team had just safely relocated the diplomatic personnel to a soccer field for airlift. The air smelled of the multiple smoke grenades they had used for cover. They looked happy it was over.

Agents make their way to a helicopter landing zone after evacuating the U.S. consulate of Erehwon. (Jahi Chikwendiu/The Washington Post)

Diplomatic Security special agents gather themselves after completing the last days of their training course in May. (Jahi Chikwendiu/The Washington Post)

The most stressful part of the past 76 hours?

“Not knowing what’s coming next,” Alex said.

That’s part of the point. A 14-year DS veteran, with posts including Thailand and Slovakia, Alex will soon head to the U.S. Consulate in Basra, Iraq — a posting that represents the service’s new reality.

“When I started in 2000, we were not in war zones,” he noted. “This is what we need to operate in a war zone. . . . It’s sort of like being in the military, yet you’re a diplomat at the same time.”

Two other graduates in his squad are also going to Iraq, which has an oversize component of diplomatic personnel — the largest U.S. Embassy in the world — but no longer a fallback army to help keep them safe (although Marines are still attached to many diplomatic posts as guards).

The post-Benghazi review board noted the Diplomatic Security Service “is being stretched to the limit as never before,” as terrorist threats escalate worldwide, including where the U.S. military has no presence. In response, the State Department will have hired 75 more agents by year’s end.

The State Department says it eventually wants all of its security agents to be trained for high-risk postings. In response to Benghazi, mid-level and executive-level agents will be put through four-week high-threat courses as well.

Many in the security service have military and law-enforcement backgrounds, but their ranks also include teachers, lawyers, scientists and linguists. All have at least bachelor’s degrees.

Although the trainees may sometimes wear and carry intimidating gear — especially the high-threat graduates, who have $7,000 more in equipment than other DS agents — the State Department stresses that their only posture is defensive.

“We provide security, and we’ve got to be able to respond. Period,” said Mark H. Hipp, the deputy assistant secretary for training.

“We are not going out looking for a fight,” said Bill A. Miller, who directs the Diplomatic Security Service and is a 27-year veteran of the force. “We try to go in keeping a low profile, when possible. . . . I’ve gone into places totally unarmed but feeling safer than if I was carrying a gun.”

Certain functions of U.S. foreign policy can’t be carried out without them. Besides moving diplomats from place to place, DS members must interact with host-nation law-enforcement counterparts and are in frequent contact with foreign dignitaries, as well as with the local populace.

Instructors monitor the in-the-field movements of instructors and students during training exercises. (Jahi Chikwendiu/The Washington Post)

During an exercise, role-playing attackers lie prone after the trainees take control of the situation. (Jahi Chikwendiu/The Washington Post)

This is particularly tricky in hot zones. “The new strategy is to continue to do diplomacy with the left hand, war fighting on the right,” said Dan McCollor, the high-threat training section chief. “And we have to figure out a way to keep our diplomats safe.”

Another post-Benghazi initiative will train and supply equipment to host-nation security officials, according to Hipp. Although they’re on the front lines, some foreign nationals who serve as guards at U.S. diplomatic facilities are not necessarily well trained or qualified.

The Libyan man who commanded the local guards at Benghazi was a former English teacher with no security background, according to Reuters. “I’ve never held a gun in my life,” he told the news agency in the weeks after the attacks by heavily armed Islamists.

During the recent Erehwon exercise, preoccupied students overlooked some unofficial extra care and feeding of a local guard, who complained of needing shade. He walked off the job, creating a security vulnerability: The guard was one of the consulate’s connections to the locals.

Trainers say nurturing such relationships is a key “soft skill” — part of the diplomatic side of the job.

Early on the morning of the simulated consulate attack, a crowd of about 25 role-players, costumed like extras in some sort of Iraqi-Afghan action flick, mounted a noisy protest with signs (“Leave Amerika”) and ululating women. They brandished shoes and a blazing burlap effigy. The head of the company that supplied the actors looked on, heeding suggestions from trainers through his radio.

The demonstration ended uneventfully, but before long, the terrorists/Marines burst onto the scene, guns blazing — or at least firing very realistic blanks.

The scenario accorded obvious advantages to the DS agents in the consulate: They were shooting from hardened, elevated positions. It was easy to slaughter attackers racing across a yard.

The would-be suicide bomber seemed confused about where to detonate. He needed some stage direction on his path to maximum destruction.

“Get inside, center door, go!” a trainer shouted.

Soon, all the men in black were playing dead and the U.S. agents wiped clean the white boards that served as “intel corner.” Lacking shredders and burn bags, they carried out classified documents in black hard-plastic cases. They lowered and carefully folded the American flag.

A squad of 16 men completed the 10-week course last month, the latest of 47 graduates since last October. Was it a success? Everyone went home alive, an agent said, so yes. (Jahi Chikwendiu/The Washington Post)

This grand finale wasn’t real, but all the instruction and practice were: 2 1 / 2 months of muscle memory that might well save lives if the real thing happened.

Instructors determined that the Americans suffered just three casualties — one on a stretcher and two who were able to walk.

So was it a success?

Everyone went home alive, said a bearded agent named Jeremiah, a former Army medic. So by that definition, yes, the mission was a success.

But in the safe, artificial aftermath, in his sweat-soaked fatigues, he also considered the future in a high-threat post. He didn’t know yet where it would be, but he knew real dangers lay ahead.

Soldiers fight the wars. But diplomats are there before wars begin, and in places like Iraq and Afghanistan, they will be there after the troops pull out.

“We’re what’s left,” Jeremiah mused. “An interesting concept.”