NAIROBI, Kenya — The soldier pointed his AK-47 at the female aid worker and gave her a choice.

"Either you have sex with me, or we make every man here rape you and then we shoot you in the head," she remembers him saying.

She didn't really have a choice. By the end of the evening, she had been raped by 15 South Sudanese soldiers.

South Sudanese soldiers are seen along a street following renewed fighting in Juba on July 10. REUTERS

On July 11, South Sudanese troops, fresh from winning a battle in the capital, Juba, over opposition forces, went on a nearly four-hour rampage through a residential compound popular with foreigners, in one of the worst targeted attacks on aid workers in South Sudan's three-year civil war.

They shot dead a local journalist while forcing the foreigners to watch, raped several foreign women, singled out Americans, beat and robbed people and carried out mock executions, several witnesses told The Associated Press.

For hours throughout the assault, the U.N. peacekeeping force stationed less than a mile away refused to respond to desperate calls for help. Neither did embassies, including the U.S. Embassy.

The Associated Press interviewed by phone eight survivors, both male and female, including three who said they were raped. The other five said they were beaten; one was shot. Most insisted on anonymity for their safety or to protect their organizations still operating in South Sudan. AP does not identify victims of sexual assault.

Related: World's Newest Nation Is 'Spiraling Out of Control'

The accounts highlight, in raw detail, the failure of the U.N. peacekeeping force to uphold its core mandate of protecting civilians, notably those just a few minutes' drive away. U.N. peacekeepers in Juba have already been accused of not acting to stop the rapes of local women by soldiers outside the U.N.'s main camp and within their sight last month.

The attack on the Terrain hotel complex shows the hostility toward foreigners and aid workers by troops under the command of South Sudan's President Salva Kiir, who has been fighting supporters of rebel leader Riek Machar since civil war erupted in December 2013. Both sides have been accused of abuses. The U.N. recently passed a U.S. resolution to send more peacekeeping troops to protect civilians.

In this photo taken on July 25, 2016, some of the more than 30,000 Nuer civilians sheltering in a United Nations base in South Sudan's capital Juba for fear of targeted killings by government forces walk by an armored vehicle and a watchtower manned by peacekeepers. Jason Patinkin / AP

Army spokesman Lul Ruai did not deny the attack at the Terrain but said it was premature to conclude the army was responsible. "Everyone is armed, and everyone has access to uniforms and we have people from other organized forces, but it was definitely done by people of South Sudan and by armed people of Juba," he said.

A report on the incident compiled by the Terrain's owner at Ruai's request, seen by the AP, alleges that at least five women were raped, torture, mock executions, beatings and looting. An unknown number of South Sudanese women were also assaulted.

The attack came just as people in Juba were thinking the worst was over.

Three days earlier, gunfire had erupted outside the presidential compound between armed supporters of the two sides in South Sudan's civil war, at the time pushed together under an uneasy peace deal. The violence quickly spread across the city.

Related: South Sudan Fighters Burned Kids Alive, Raped Girls as Pay

Throughout the weekend, bullets whizzed through the Terrain compound, a sprawling complex with a pool, squash court and a bar patronized by expats and South Sudanese elites. It is also in the shadow of the U.N.'s largest camp in Juba.

By Monday, the government had nearly defeated the forces under Machar, who fled the city. As both sides prepared to call for a cease-fire, some residents of the Terrain started to relax.

"Monday was relatively chill," one survivor said.

What was thought to be celebratory gunfire was heard. And then the soldiers arrived. A Terrain staffer from Uganda said he saw between 80 and 100 men pour into the compound after breaking open the gate with gunshots and tire irons. The Terrain's security guards were armed only with shotguns and were vastly outnumbered. The soldiers then went to door to door, taking money, phones, laptops and car keys.

A photo from South Sudan taken July 13, 2016, and released by the United Nations Mission. Eric Kanalstein / AP

"They were very excited, very drunk, under the influence of something, almost a mad state, walking around shooting off rounds inside the rooms," one American said.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

One man wore a blue police uniform, but the rest wore camouflage, the American said. Many had shoulder patches with the face of a tiger, the insignia worn by the president's personal guard.

For about an hour, soldiers beat the American with belts and the butts of their guns and accused him of hiding rebels. They fired bullets at his feet and close to his head. Eventually, one soldier who appeared to be in charge told him to leave the compound. Soldiers at the gate looked at his U.S. passport and handed it back, with instructions.

"You tell your embassy how we treated you," they said. He made his way to the nearby U.N. compound and appealed for help.

Meanwhile, soldiers were breaking into a two-story apartment block in the Terrain which had been deemed a safe house because of a heavy metal door guarding the apartments upstairs. Warned by a Kenyan staffer, more than 20 people inside, most of them foreigners, tried to hide. About 10 squeezed into a single bathroom.

The building shook as soldiers shot at the metal door and pried metal bars off windows for more than an hour, said residents. Once inside, the soldiers started ransacking the rooms and assaulting people they found.

South Sudanese women and children line up on July 25 to receive emergency food at the United Nations protection of civilians site 3 hosting about 30,000 people displaced during the recent fighting in Juba. ADRIANE OHANESIAN / Reuters

Some of the soldiers were violent as they sexually assaulted women, said the woman who said she was raped by 15 men. Others, who looked to be just 15 or 16 years old, looked scared and were coerced into the act.

"One in particular, he was calling you, 'Sweetie, we should run away and get married.' It was like he was on a first date," the woman said. "He didn't see that what he was doing was a bad thing."

After about an hour and a half, the soldiers broke into the bathroom. They shot through the door, said Jesse Bunch, an American contractor who was hit in the leg.

"We kill you! We kill you!" the soldiers shouted, according to a Western woman in the bathroom. "They would shoot up at the ceiling and say, 'Do you want to die?' and we had to answer 'No!'"

The soldiers then pulled people out one by one. One woman said she was sexually assaulted by multiple men. Another Western woman said soldiers beat her with fists and threatened her with their guns when she tried to resist. She said five men raped her.

Related: U.N. Report Details Horrific Crimes in War-Ravaged South Sudan

During the attack on the Terrain, several survivors told the AP that soldiers specifically asked if they were American. "One of them, as soon as he said he was American, he was hit with a rifle butt," said a woman.

When the soldiers came across John Gatluak, they knew he was local. The South Sudanese journalist worked for Internews, a media development organization funded by USAID. He had taken refuge at the Terrain after being briefly detained a few days earlier. The tribal scars on his forehead made it obvious he was Nuer, the same as opposition leader, Riek Machar.

"All it took was a declaration that he was different, and they shot him mercilessly"

Upon seeing him, the soldiers pushed him to the floor and beat him, according to the same woman who saw the American beaten.

Later in the attack, and after Kiir's side declared a ceasefire at 6 p.m., the soldiers forced the foreigners to stand in a semi-circle, said Gian Libot, a Philippines citizen who spent much of the attack under a bed until he was discovered.

One soldier ranted against foreigners. "He definitely had pronounced hatred against America," Libot said, recalling the soldier's words: "You messed up this country. You're helping the rebels. The people in the U.N., they're helping the rebels."

During the tirade, a soldier hit a man suspected of being American with a rifle butt. At one point, the soldier threatened to kill all the foreigners assembled. "We're gonna show the world an example," Libot remembered him saying.

Then Gatluak was hauled in front of the group. One soldier shouted "Nuer," and another soldier shot him twice in the head. He shot the dying Gatluak four more times while he lay on the ground.

A photo taken July 13 and released by the United Nations Mission in South Sudan shows villagers and internally displaced people being helped by UN soldiers in Juba, South Sudan. Eric Kanalstein / AP

"All it took was a declaration that he was different, and they shot him mercilessly," Libot said.

The shooting seemed to be a turning point for those assembled outside, Libot said. Looting and threats continued, but beatings started to draw to a close. Other soldiers continued to assault men and women inside the apartment block.

From the start of the attack, those inside the Terrain compound sent messages pleading for help by text and Facebook messages and emails.

"All of us were contacting whoever we could contact. The U.N., the U.S. embassy, contacting the specific battalions in the U.N., contacting specific departments," said the woman raped by 15 men.

A member of the U.N.'s Joint Operations Center in Juba first received word of the attack at 3:37 p.m., minutes after the breach of the compound, according to an internal timeline compiled by a member of the operations center and seen by AP.

Eight minutes later another message was sent to a different member of the operations center from a person inside Terrain saying that people were hiding there. At 4:22 p.m., that member received another message urging help.

Five minutes after that, the U.N. mission's Department of Safety and Security and its military command wing were alerted. At 4:33 p.m., a Quick Reaction Force, meant to intervene in emergencies, was informed. One minute later, the timeline notes the last contact on Monday from someone trapped inside Terrain.

For the next hour and a half the timeline is blank. At 6:52, shortly before sunset, the timeline states that "DSS would not send a team."

About 20 minutes later, a Quick Reaction Force of Ethiopians from the multinational U.N. mission was tasked to intervene, coordinating with South Sudan's army chief of staff, Paul Malong, who was also sending soldiers. But the Ethiopian battalion stood down, according to the timeline. Malong's troops eventually abandoned their intervention too because it took too long for the Quick Reaction Force to act.

"The peacekeepers did not venture out of the bases to protect civilians under imminent threat"

The American who was released early in the assault and made it to the U.N. base said he also alerted U.N. staff. At around dusk, a U.N. worker he knew requested three different battalions to send a Quick Reaction Force.

"Everyone refused to go. Ethiopia, China, and Nepal. All refused to go," he said.

Eventually, South Sudanese security forces entered the Terrain and rescued all but three Western women and around 16 Terrain staff.

No one else was sent that night to find them. The U.N. timeline said a patrol would go in the morning, but this "was cancelled due to priority." A private security firm rescued the three Western women the staffers the next morning.

When asked why the U.N. peacekeeping mission didn't respond to the repeated requests for help, acting spokeswoman Yasmina Bouziane said the circumstances are under investigation.

"The peacekeepers did not venture out of the bases to protect civilians under imminent threat," Human Rights Watch said Monday in a report on abuses throughout Juba.

The U.S. Embassy, which also received requests for help during the attack, did not respond to repeated requests for comment.

The assault at the Terrain pierced a feeling of security among some foreigners who had assumed that they would be protected by their governments or the hundreds of U.N. peacekeepers almost next door.

One of the women gang-raped said security advisers from an aid organization living in the compound told residents repeatedly that they were safe because foreigners would not be targeted. She said: "This sentence, 'We are not targeted,' I heard half an hour before they assaulted us."