South Sudan’s rival leaders on Thursday announced they have agreed to form a coalition government just two days before the latest deadline, a major step in the emergence from a five-year civil war that killed nearly 400,000 people and shattered life in the world’s youngest nation.

The rival leaders had twice missed deadlines in the past year to form the transitional government that is expected to lead to elections in three years’ time, much to the impatience of the United States and others. Without that new government, many feared, South Sudan might slide into fighting again.

Opposition leader Riek Machar told reporters in the capital, Juba, he and President Salva Kiir agreed that after the government’s formation they will resolve any outstanding issues laid out in a September 2018 peace deal. He said he is confident they will address them all.

Kiir said the new government will be formed on Saturday and that he will appoint Machar as his first vice president, or top deputy, on Friday. That arrangement has twice led to conflict — once when the civil war erupted in late 2013 and again in mid-2016 after Machar returned to the post under a previous peace deal. He ended up fleeing the country on foot.

The president said security arrangements, one key issue, will be resolved after the government’s formation. He added that the protection of Machar and others from the opposition will be under his responsibility.

These changes are for the sake of peace to prevail, Kiir said. And he called on the more than 2 million people who fled South Sudan during the conflict to finally come home.

South Sudan's civil war broke out just two years after the nation danced in the streets to celebrate a long-fought independence from Sudan. The conflict badly hurt the oil-rich nation's economy, and roughly half the country's 12 million people are hungry today.

Major challenges in the peace process remain, including the delicate process of integrating tens of thousands of former rival forces into a united army. That process has been marked by delays, the United Nations and others have said, noting that some of the forces appear to be poorly provisioned.

And widespread abuses such as the recruitment of child soldiers and sexual violence continue, a new report by the U.N. Commission on Human Rights on South Sudan said Thursday.

Cara Anna in Johannesburg contributed.