Rebel leader Riek Machar, center, shakes hands with South Sudanese President Salva Kiir after lengthy peace negotiations in Addis Ababa, Ethi­o­pia, on Aug. 17. (Mulugeta Ayene/AP)

South Sudan’s president signed a peace deal Wednesday intended to end a 20-month-old civil war that has left thousands dead in the wake of the country’s historic declaration of independence in 2011.

President Salva Kiir decided to support the accord after coming under intense pressure from the international community, which threatened to impose further sanctions if the deal was not completed before September. Rebel leader Riek Machar, Kiir’s former deputy, had signed the document one week earlier.

In signing the deal, Kiir alluded to the pressure he faced, saying he had “serious reservations.”

“With all those reservations that we have, we will sign this document,” he said Wednesday at a gathering attended by numerous African leaders.

Not long after becoming the world’s newest country, South ­Sudan became embroiled in a bitter conflict, which played out mostly along ethnic lines. There have been numerous reports of children being killed or forced to fight, women being raped and people being slain en masse.

A report by the United Nations this week described how both sides had managed to supply themselves with arms and ammunition, escalating the war and “leading to large-scale violations of international humanitarian law.”

With the country awash in weapons and tensions still strong, delivering on the promises of the peace agreement may prove to be a challenge. In the past, Kiir and Machar have agreed to several cease-fires — but each of them has crumbled.

The deal reached Wednesday allows for a power-sharing arrangement, which is likely to restore Machar to the position of vice president and permit the rebels to appoint two state governors.

The last time Machar was vice president, in 2013, Kiir accused him of plotting a coup. Fighting broke out between ethnic Dinka and Nuer members of the presidential guard in Juba, the capital. Kiir is a Dinka, while Machar is from the Nuer group. The violence then spread to other parts of the country.

Even though Kiir and Machar fought together for their nation’s independence from Sudan, they have long feuded about how South Sudan should be governed. It is unclear whether they can now heal the country’s ethnic rift, particularly as Kiir expressed serious doubts before signing the deal.

“The current peace we are signing today has so many things we have to reject,” he said.

Still, experts praised the role played by the United States and other members of the international community in bringing both sides to the negotiating table. The process appeared to be derailed last week, when Kiir missed an earlier deadline for signing, prompting national security adviser Susan E. Rice to say, “The U.S. deplores this failure of leadership.”

The United States was intimately involved in South Sudan gaining independence, and it has since provided millions of dollars in civilian aid and military assistance. As South Sudan’s conflict simmered, the White House found itself trying to support one of the world’s poorest nations while working to ensure that its funds were not being diverted to fuel the civil war. It imposed targeted sanctions, which many people say were effective.

The United States had threatened more-robust sanctions unless Kiir and Machar signed the deal, and the United Nations also warned of penalties.

President Obama’s direct engagement with regional leaders during his trip to Africa in late July was essential in cultivating what had been missing so far in the negotiations — international leverage aimed at pressuring the warring parties toward peace,” said John Prendergast, founder of the Enough Project, a nonprofit organization that does research on South Sudan.

About 2 million people have been left homeless since the conflict broke out in late 2013.

The country has teetered on the brink of famine and has presented an immensely difficult environment for aid organizations. Doctors Without Borders reported that two of its employees were killed in Unity state last week.

“The situation is desperate. Ongoing attacks, killings and sexual violence against civilians by any armed actor in Unity state must stop,” said Tara Newell, the group’s emergency manager. “People displaced from their homes and villages should be able to move safely to seek assistance, wherever it is being provided.”

The economy has suffered, too, despite South Sudan’s significant oil reserves. The country has a debt of more than $4 billion.

Read more:

The U.N. says South Sudanese soldiers gang-raped girls and then burned them alive

Talking about war makes it more likely: look at South Sudan

South Sudan’s president said critica journalists could be killed. Four days later, one was