South Sudan, the world’s youngest country, has received more than $1bn in humanitarian aid every year from the United States and the United Nations. It gained independence in 2011 with the strong support of the Bush and Obama administrations.

But in 2013, civil war broke out between forces loyal to President Salva Kiir and supporters of his former deputy, Riek Machar, who are known as the rebels. While both sides have been accused of atrocities, the UN says the majority have been committed by government soldiers.

A peace deal brokered by the US and the international community collapsed in July 2016.

Until the summer of 2016, South Sudan’s Yei region was a leafy oasis in the midst of the country’s civil war. But when a national peace deal broke down, and government soldiers ransacked the area, a handful of UN and US officials begged their leaders for help.

They argued that the UN must send peacekeepers to Yei to protect civilians from Kiir’s forces, who were burning villages and slaughtering men, women and children. And that the US needs to change its approach in the face of a potential genocide, they warned.

The pleas were ignored. The UN did not send peacekeeping troops to Yei, and the US continued to support South Sudan’s military, possibly in violation of US law, an AP investigation found.

The investigation is based on more than 30 internal or confidential documents from the UN, White House and US Department of State, as well as dozens of interviews with current or former officials and civilians.

In a matter of weeks, Yei became the centre of a nationwide campaign of what the UN calls ethnic cleansing, which created the largest exodus of civilians in Africa since the Rwandan genocide in 1994. More than 1 million people have now fled to Uganda, mostly from the Yei region. And while there is no tally for how many people have died in South Sudan, estimates put the number in the tens or even hundreds of thousands.

Kate Almquist Knopf, director at the Africa Center for Strategic Studies at the US Department of Defense, compared the situation in South Sudan to Rwanda, where nearly a million people died in 100 days with little action from the US or the international community.

“The same thing is happening now in South Sudan,” she said. “It’s happening on Africa’s watch. It’s happening on America’s watch. It’s happening on the United Nations’ watch.”

More than a year later, the UN says it is still considering sending a permanent peacekeeping force to Yei if it gets more troops. The UN now has about 12,000 peacekeepers throughout South Sudan, but US officials say it would take roughly 40,000 to secure the country. That leaves Yei and other major population centres - such as Bentiu, Malakal and Wau - vulnerable.

“There are always discussions,” said Daniel Dickinson, a spokesperson for the U.N. mission in South Sudan. “It’s all about what resources the mission has available.”

For its part, the US had budgeted $30 million for technical training, non-lethal equipment and advisers to South Sudan’s military for the 2016 and 2017 fiscal years. The State Department in July gave a further $2 million for a military and security operations centre that supported the country’s security service and presidential guards.

The assistance appears to violate a US law prohibiting support to any unit that has committed a gross violation of human rights - in this case including an attack on a popular hotel that targeted aid workers and American citizens. South Sudanese soldiers have killed a journalist, gang raped women and conducted mock executions of civilians and aid workers.

A spokesperson for the State Department said military officials who received assistance “were vetted and not credibly implicated in the gross violation of human rights.” They added the US had exerted pressure on both the government and the rebels to stop fighting.

However, the US aid is a “red flag,” said Sen. Patrick Leahy, who sponsored the law. “The South Sudanese security forces, like their rebel counterparts, are notorious for violating human rights without fear of being punished. We do not want the United States to be associated with such misconduct.”

In 2016, government troops rampaged through the town of Nyori in the Yei region, according to a former local official, who spoke on condition of anonymity because he feared retribution. He ran into the bush to hide and returned three days later to carnage.

“I witnessed with my own eyes, young children, they were slaughtered,” he said.

Rose Kiden fled from a town near Yei when soldiers swarmed her house. In a hushed voice, Kiden recounted how she came back to find her sister on the floor; she had been raped by eight soldiers. Kiden said she knew six other women who were raped by soldiers.

Her husband was killed by government troops when he went to collect food. But even as the violence near Yei spread, Kiden said, UN vehicles drove by without stopping.

“They didn’t do anything,” Kiden said, as she held her baby, who now has no father. “They just passed.”

When UN officials visited Yei in September 2016, they were horrified by stories of women gang raped and a baby hacked with a machete.

“If the security situation is not rapidly stabilized, the protection crisis in Yei will swiftly become a multi-faceted humanitarian crisis,” said a UN report from September 15, obtained by AP, to the head of the UN mission in South Sudan at the time, Ellen Loj.

After nearly two months, the UN started sending small, temporary patrols to Yei. But both residents and UN officials said the violence merely continued after the blue helmets left. In late October 2016, a UN patrol remained on the ground for only three days.

In November, the AP saw seven corpses inside a hut, where local officials said people had been arrested, trapped and burned alive. One charred body was slouched against a wall with its arms and legs missing, and another lacked a torso.

On November 11, special adviser Adama Dieng warned about “the potential for genocide” and highlighted the violence in Yei.

“One person reported desperately to me, ‘Tonight I don’t know what will happen to me,’” Dieng said at the time.

That month, the UN decided not to send a permanent force to Yei. When asked why at her farewell press conference on November 28, Loj said the UN did not have enough troops. She said Yei would be next to get peacekeepers.

“But I don’t know when it will be possible,” she added. “South Sudan is a big country, and we cannot have a soldier behind each and every South Sudanese.”

In the meantime, South Sudan’s government blocked or harassed UN officials dozens of times per month, according to confidential UN documents. UN officials told the AP that the mission should have sent peacekeepers into Yei anyway.

“This is what the peacekeepers were there for,” said Donatella Rovera, a crisis adviser at Amnesty International. “There was a failure to do what needed to be done at the time it needed to be done.”

During another UN visit in February this year, a community leader from the Yei area said he had begged for peacekeepers three times in the past few weeks.

“We need imminent protection before it’s too late,” he said, according to an internal report. “If we get killed because we told you the truth today so be it.”

Hours later the UN left.

The South Sudan government has denied ethnic cleansing and human rights violations.

“All these reports that go to the UN are written by individuals who are anti-peace in South Sudan,” said Minister of Information Michael Makuei.

The US also struggled to respond to the crisis in South Sudan, according to documents and interviews.

In July 2016, the South Sudanese military fired dozens of bullets into two US embassy vehicles. The same month, government troops rampaged through a hotel, killing a journalist, gang raping women and beating people, including Americans.

Still, the US continued to believe it could fix South Sudan’s military. In September, President Barack Obama sought a “long-term military to military relationship” with South Sudan, according to a letter to Congress obtained by AP. The letter, which allowed military training and education for South Sudan’s army, circumvented a law blocking US support for countries that use child soldiers.

“Once again in South Sudan, we have shown a pattern of having bad analysis, either ignoring the symptoms of the problem entirely, not seeing them, or analysing them in the wrong way,” said Cameron Hudson, director of African affairs at the National Security Council in the Bush administration.

One State Department official was more blunt.

“We just don’t have a policy,” said the official, who asked to remain anonymous because he was not authorised to speak to reporters. “There is no game plan.”

The centrepiece of the US response to South Sudan was a push for an additional 4,000-strong UN peacekeeping force to protect civilians under attack. The US got the force approved by the Security Council. At a press conference in South Sudan in September 2016, Samantha Power, then US ambassador to the UN, described an agreement with President Kiir on the extra 4,000 peacekeepers, known as the Regional Protection Force.

“We came to get consent to the RPF, and that is a consent that has been given,” said Power, the Pulitzer Prize-winning author of a book that details America’s failure to prevent genocide in Germany, Rwanda and the Balkans. “The details have to be worked through.” If the government didn’t accept the troops, Power warned, the Security Council would place an arms embargo on the country.

But in a stark reversal, as Power left the next morning, South Sudan’s government denied having ever accepted the extra 4,000 peacekeepers.

“I think the government won the game,” South Sudanese Cabinet Minister Martin Lomuro bragged to reporters.

One State Department official described Power’s visit as “supremely embarrassing” because of the public failure. Others doubted that she was fooled by South Sudan’s leaders. Power declined requests for comment.

In the fall, a dissent cable drafted within the State Department argued that US support for the peace deal and failure to act was fueling violence.

“Further calamity is likely; the risks of famine, continued mass atrocities, and genocide are among the highest in the world,” the draft cable said. The risks of not changing US policy, it continued, “are immediate and unacceptably high.” The draft was never finalised because it did not gain enough support, two US officials said.

Senior Obama administration officials said pulling out of the country’s peace deal would have created even more violence, and there was a limit to what the US could accomplish without partners in the African Union.

Others disagree. The US gave “tacit endorsement” to South Sudan’s government, according to Alan Boswell, a researcher on South Sudan.

US policy “did not start the violence, but it meant that we were not going to try and stop it,” Boswell said.

Today, more than 18,000 homes have been destroyed in Yei, UN satellite images show.

Yei is in danger of famine. Hundreds of people have died, and many more have fled, creating the world’s largest refugee camp in Uganda, Bidi Bidi. Government forces attacked some even as they tried to escape.

“When women went to collect food at farms, the soldiers raped people, raping everyone,” said Simon Nigo, a refugee at Bidi Bidi. “No protection for the civilians.”

A pastor from Yei, who spoke on condition of anonymity for fear of retribution from South Sudanese intelligence officials, came to Bidi Bidi after the military took over the orphanage he ran. He said the charred bodies the AP discovered in the burned house on the outskirts of Yei were his relatives.

His bible is inscribed with the word “Redemption,” promising revenge. Like others at Bidi Bidi, he said he felt abandoned by the UN and the world.

“They could have protected people’s lives,” he said. “They could have saved us from coming to this camp.”