South Sudan's government and rebels have signed a ceasefire to end more than five weeks of fighting that divided Africa's newest nation and brought it to the brink of civil war.
Fighting between troops loyal to President Salva Kiir and those backing the vice president he sacked in July, Riek Machar, erupted in mid-December.
I believe that the postwar challenges will be greater than the war itself. The process will be ... unpredictable and delicate.
Thousands of people have been killed and more than half a million people have fled their homes, prompting the regional grouping of nations, IGAD, to initiate peace talks.
The pact is expected to be implemented within 24 hours of the signing, mediators said.
But making the ceasefire hold could test Machar, whose forces include loyalists as well as more autonomous groups battling the centrally controlled government forces.
"The crisis that gripped South Sudan is a mere manifestation of the challenges that face the young and fledgling state," Seyoum Mesfin, IGAD's chief mediator, told the signing ceremony.
"I believe that the postwar challenges will be greater than the war itself. The process will be ... unpredictable and delicate."
The conflict quickly deteriorated into all-out war between the regular army, who are being backed by Ugandan troops, and defectors and ethnic militia, with the violence also pitting some members of Kiir's Dinka tribe against some from Machar's Nuer group.
Detainees still held
Both sides had previously said they were close to a deal, but disagreements had until now pushed back any signing.
Rebels had demanded the release of 11 of Machar's allies, detained by the government and accused of attempting a coup. Seyoum, the chief mediator, told reporters the deal provided for the 11 to eventually participate in the peace process but that they must first face due process of law.
|Analysis: Ceasefire the best news for South Sudan in weeks
Shortly before the signing, rebel spokesmann, Mabior Garang, said freeing the detainees was "not so much of a demand since everyone recognises the need for their release".
Diplomats at the talks had said the deal would call for an end to "involvement by foreign forces", but Hussein Mar Nyot, the spokesman for Machar's delegation, said it called for a "withdrawal of allied forces invited by both sides".
Government forces have retaken control of major towns that had been captured by rebels, though often with the assistance of Ugandan forces.
South Sudan won its independence from Sudan in 2011 after decades of conflict between the northern and southern Sudanese.