South Sudanese President Salva Kiir agreed Friday to attend peace talks with his rival in a political and military conflict that has killed thousands and threatened the future of the world’s newest nation, Secretary of State John F. Kerry said.

Kiir agreed to meet as soon as next week with rebel leader Riek Machar in the nearby Ethiopian capital, Kerry said after a meeting at Kiir’s office that ended with a friendly handshake. Kiir, trademark cowboy hat in place, waved from the top of the stairs as Kerry left.

Kiir also pledged to end fighting under terms of a four-month-old cease-fire that never took hold, Kerry said, and accepted in principle that South Sudan should institute a transitional government to bridge the current political gulf and hold new elections.

“I made it clear to him that he has to do everything in his power to end violence and also begin the process of national dialogue,” Kerry told reporters.

Kiir and Machar have promised in the past to end fighting that began in December when Kiir accused Machar, the former vice president, of trying to stage a coup. There was no immediate word from Kiir’s office about the assurances Kerry said he was given that this time will be different.

By pursuing sectarian and personal rivalries, the two sides risk squandering their birthright just three years after independence from Sudan, Kerry said. Kiir and Machar have not met since the conflict began.

“If both sides do not take steps in order to reduce or end the violence, they literally put their entire country in danger,” Kerry said.

Thousands have died since the split in the South Sudanese government quickly became open warfare between government forces and rebels. The conflict has increasingly taken on ominous ethnic and sectarian tones, pitting Kiir’s Dinka ethnic group against Machar’s Nuer people.

The State Department said that Kerry called Machar on Friday but that Machar did not commit to join Kiir at the talks.

“I told President Kiir that the choices that both he and the opposition face are stark and clear,” Kerry said. “The unspeakable human costs that we have seen over the course of the last months, and that could even grow if they fail to sit down, are unacceptable.”

Kerry flew to the ragtag capital in a heavy military transport plane and under tight security. Deteriorating conditions throughout the country led to an evacuation of the U.S. Embassy in January, and it is now operating with reduced staff.

“Before the promise of South Sudan’s future is soaked in more blood, President Kiir and the opposition must work immediately for the cessation of hostilities,” Kerry said.

He repeated the threat of U.S. economic sanctions if the fighting does not stop.

A day earlier in Ethiopia, Kerry said he and East African leaders had agreed on the outline of an African military force that could separate the warring factions.

A senior State Department official traveling with Kerry said the troops would be under U.N. command and that the U.N. Security Council would have to approve a new, larger mandate than the one held by the current force of several thousand peacekeepers.

The official spoke on the condition of anonymity because the agreement is not complete.

The military force would number 2,500 initially and could be in place within weeks, Kerry said Friday.

Even at full strength of 5,500, however, it is not clear whether that force would be large enough or strong enough to stop massacres and targeted killings like the ones the United Nations has blamed on both sides.

Both sides have also been implicated in rapes and in the recruitment of child soldiers.

The United States was instrumental in helping South Sudan gain independence from Sudan in 2011 and has spent nearly $500 million to support the new government over the past two years.

Last week, the U.N. Security Council also raised the threat of sanctions against both sides.