The deal is designed to pave the way for a final peace accord that will give President Salva Kiir and his rival Riek Machar three months to form a transitional government which will hold power for 36 months.
South Sudanese arch-foes signed a final power-sharing deal on Sunday as President Salva Kiir called for unity in a country torn by a civil war that has killed tens of thousands of people.
Kiir and his bitter rival Riek Machar were in neighbouring Sudan to sign the deal, under which the rebel leader is set to return to a unity government as the first of five vice presidents.
The deal, which paves the way to a final peace accord aimed at ending the war in the world's youngest country, was signed in the presence of Sudanese President Omar al-Bashir and his counterparts from Kenya, Uganda and Djibouti, along with foreign diplomats.
Once a final peace deal is signed, the foes will have three months to form a transitional government which will then hold power for three years.
The talks come as part of a regional push aimed at achieving peace in South Sudan, which plunged into a devastating conflict just two years after its independence from Sudan in July 2011.
"The agreement we have just signed today must map the end of conflict and war in our country," Kiir said after signing the deal.
"We should ... rededicate ourselves to unite our people and work for peaceful transfer of power through the ballot boxes rather than through bullets."
Machar urged the regional east African bloc Intergovernmental Authority on Development (IGAD), which is pushing the latest peace talks, to ensure that the deal is implemented.
"I would urge ... IGAD to focus after this on the implementation of the agreement," Machar said in his address.
"Somebody said that the devil sometimes is embedded in the implementation."
South Sudan's nearly five-year conflict began after Kiir accused his then-vice president Machar of plotting a coup against him in 2013.
Kiir and Machar's factions have already agreed on a permanent ceasefire and withdrawal of their forces from urban areas, in the latest talks hosted by Bashir.
The power-sharing deal lays out a plan for a 35-minister transitional government including 20 Kiir allies and nine backers of Machar, along with representatives of other rebel factions.
The parliament will be comprised of 550 lawmakers, including 332 from Kiir's group and 128 from Machar's faction.
Kiir warned that the bloated size of the government would pose a challenge.
"See the size of the parliament, see the size of the cabinet. How do you pay them?" he said, adding that he was concerned about how to provide housing, offices and cars for new officials.
But Sudan's Bashir said the mediators were committed to ensure that the agreement was implemented.
He said his personal aim was to ensure that South Sudan could restart production of oil from oil-rich Unity State by September 1.
Nearly five years of war have seen South Sudan's oil production plummet to about 120,000 barrels a day from a peak of 350,000, according to the World Bank.
Political analyst, Ayesha Kajee believes both leaders need to learn from South Sudan's violent past.
Washington has been sceptical about the success of the latest peace initiative, given the enmity between Kiir and Machar.
Last month the White House warned that "a narrow agreement between elites" would not solve the problems plaguing South Sudan.
"In fact, such an agreement may sow the seeds of another cycle of conflict," it said.
But on Sunday the top US envoy to Khartoum said the US backed the process.
"We are supporting any initiative to bring peace to South Sudan and we hope this process will continue comprehensively," US Charge d'Affaires in Khartoum, Steven Koutsis, told reporters after Sunday's deal was signed.
The United Nations said the power-sharing deal was a "significant step."
"By signing this agreement the guns must keep silent," said Nicholas Haysom, special UN envoy to Sudan and South Sudan.
A similar peace deal was signed in 2015 but fell apart a year later in a deadly battle that saw Machar flee into exile.
South Sudan's war dashed the optimism that accompanied independence from Sudan in 2011.
The new country plunged into civil war, including fighting within the national army, fuelled by the deep enmity between the two leaders.
The war has killed tens of thousands, displaced some four million people and left the oil-rich country's economy in ruins.
With the country's agricultural sector severely disrupted, seven million South Sudanese – more than half of the population – will need food aid in 2018, the United Nations says.