In this photo taken Aug. 3, bullet holes are seen in a metal door that was shot open at the Terrain compound during looting the previous month in Juba, the capital of South Sudan.  (Adriane Ohanesian via AP)

When a spasm of violence broke out in South Sudan's capital last month, a group of foreign aid workers faced a fateful decision: Should they try to flee the country or go into lockdown?

The consensus they reached was that it was too dangerous to leave their compound, known as Terrain. "There was a lot of gunfire nearby," said Gian Libot, a Philippine aid worker. "But it wasn't directed at us. We were under the impression that we weren't the target of any of the fighting."

After two days cooped up in Terrain's safehouse, that impression was shattered when gunfire erupted at the gate of the compound. The mood among the dozens of foreigners and South Sudanese inside went from confusion to concern to panic in minutes. Seeking protection, they frantically called contacts at embassies and the U.N. peacekeeping mission, which happened to be just down the road.

Libot sought refuge in a room with a few others. He hid under a bed for two hours, watching the boots of soldiers pace on the floor in front of him. They barked death threats at his colleagues. An Associated Press report this week detailed how, in other rooms of the compound, 80 to 100 armed men "raped several foreign women, singled out Americans, beat and robbed people and carried out mock executions" for nearly four hours. One woman was raped by 15 men.

When Libot was finally discovered, he was hit with a rifle butt on his back and was ushered into a hallway, where a soldier told the group that he would kill them as a warning to foreigners, particularly Americans, to stop meddling in his country. Instead, the soldiers shot John Gatluak, a South Sudanese journalist working for a nongovernmental organization focused on media development. "They singled him out because he was Nuer," said Libot, referring to Gatluak's ethnicity.

The attack at Terrain is the latest in the seemingly endless stream of horrors befalling civilians in South Sudan. And as with several cases in the past, this one has left many asking: Where was the U.N. peacekeeping force that had been called multiple times for help? Given that it has a mandate to protect civilians and to use force if necessary, how did a brazen assault go on for hours so close to the peacekeepers' base?

On Tuesday, U.N. Secretary General Ban Ki-moon announced that his office would be asking the same question. In a statement, he said he was "alarmed" at the attack on Terrain and concerned that the U.N. mission there, known by the acronym UNMISS, "did not respond appropriately to prevent this and other grave cases of sexual violence committed in Juba," South Sudan's capital. His office will open an "independent special investigation to determine the circumstances surrounding these incidents and to evaluate the Mission’s overall response."

Last Friday, the U.N. Security Council approved the deployment of 4,000 more peacekeepers to South Sudan. They will be asked to take more “proactive” measures to protect civilians. With the Terrain attack in mind, this move raises another question: Is the U.N. mission there failing to act because it is undermanned or because of a deeper set of systemic flaws?

A recent UNMISS investigation after a massacre in another part of South Sudan seems to indicate the latter.

On Feb. 17, fighters with AK-47s and grenade launchers broke into a camp for displaced people in the northern town of Malakal. As many as 50 civilians were fatally shot, burned alive in their tents or crushed to death by panicking crowds. U.N. peacekeepers fled their posts.

A summary of the UNMISS “board of inquiry report” said the organization and its peacekeepers failed through a “combination of inaction, abandonment of post and refusal to engage.”

Some peacekeepers reportedly demanded written permission to use their weapons, even though their U.N. mandate clearly gives them that authority.

Perhaps more important, peacekeepers did not heed warnings that violence was brewing and were not prepared to act, the report said. This lack of foresight and risk management seems to have been repeated in Juba during the Terrain attack.

To be fair, U.N. peacekeepers are facing an almost impossible task in South Sudan. In the civil war there, neither side has shown much regard for the safety of civilians. More than 160,000 civilians live in U.N. camps for the internally displaced. Those camps are routinely raided, often by government-backed troops. It is rare for U.N. peacekeepers to be tasked with protecting civilians against their own government's troops.

Then again, the violence that engulfed Juba wasn't entirely unpredictable. Troops loyal to South Sudan's president and vice president, who represent rival Dinka and Nuer ethnic groups, respectively, were in the city together for the first time in months. The tension was palpable, and everyone had AK-47s. A small scuffle was all that was needed to spark something larger, and that is what happened. A peace deal signed last year might as well have been scratch paper. Hundreds of troops and civilians died in two days of intense battles. Two Chinese peacekeepers were killed near the U.N. base. Government security forces raped dozens of South Sudanese women.

This Aug. 3 photo shows the damage to the Terrain compound, in the South Sudanese capital, Juba, from its looting last month. (Adriane Ohanesian via AP)

If anything, UNMISS failed to recognize that Terrain might be a target. The aid workers there didn't think they would be targeted, either. But what they and the private security contractors hired by their aid organizations may not have realized is that renegade factions of South Sudan's army harbored violent resentment toward foreigners operating in the country.

Salva Kiir, South Sudan's president and leader of its army, acknowledged that not all of his soldiers were "completely subordinate to the authority of a civilian government."

A State Department official said it was likely that troops not under Kiir's control were responsible for the attack at Terrain, adding that it was conceivable that members of South Sudan's National Security Service — its intelligence organization — also took part. Aid workers recounted that almost all the attackers at Terrain were in army uniforms and that some had insignia worn by Kiir's personal guard.

More damning, however, is a timeline of events compiled by the U.N. Joint Operations Center and obtained by the AP. The timeline details multiple units of peacekeepers refusing to be deployed to Terrain despite repeated calls for help.

Ultimately, it was not until about four hours after UNMISS was notified of the attack that South Sudanese troops under Kiir's control entered Terrain and rescued most of those inside.

The U.S. Embassy was instrumental in spurring South Sudan's army to send those troops, even if they were not able to reach the compound before many atrocities had been committed. When Molly Phee, the U.S. ambassador to South Sudan, was informed of the attack, she contacted the National Security Service and Kiir's presidential guard.

"Some of the security forces had lost control over some of their men. Those who remained under control of the generals were who we called upon for assistance," Phee said on the phone from Juba. "Generals had to find trusted troops. Then those troops had to make their way through the fighting."

The U.S. Agency for International Development, which partners with and funds the nongovernmental organization for which Gatluak and others at Terrain worked, said it was "reviewing the incident to determine how we can further support the security of our partners." The organization said that its partners are required to have security plans in place as "part of their award" and that USAID project funding goes toward security.

The irony that troops loyal to a government that relies on U.S. funding to survive attacked aid workers funded by American taxpayer money was not lost on those who spoke with The Washington Post.

Libot, the man who hid under a bed during the attack, says he is disappointed by the peacekeepers' dereliction of duty.

"This isn't the first time this has happened," he said. "I was just trusting in people who I thought knew better."

Read more:

In South Sudan, bodies are being counted as peace accord appears to unravel

The U.S. midwifed South Sudan five years ago. Now it is on the brink of falling apart.

A muddy field in South Sudan is at the center of an intractable war