South Sudan's government and rebels have signed a ceasefire agreement.

The sides have pledged to halt fighting within 24 hours.

Thousands have been killed in intense fighting in the past month between the government forces of President Salva Kiir and rebels loyal to ousted vice president Riek Machar.

Thousands more were displaced by the violence and forced to take shelter in temporary refugee camps.

The agreement was signed in front of regional mediators, diplomats and reporters in the Ethiopian capital, Addis Ababa.

Mediators from the East African regional bloc IGAD, which has been brokering the peace talks, said the deal also includes a verification and monitoring mechanism for the ceasefire.

South Sudan's government also agreed to release 11 officials close to Mr Machar who were detained after fighting broke out on 15 December.

The status of the detainees has been a major sticking point in the talks, although no timeline for their release was given.

"These two agreements are the ingredients to create an environment for achieving a total peace in my country," said Taban Deng, head of the rebel delegation.

He said he hoped the deal would "pave the way for a serious national political dialogue aiming at reaching a lasting peace in South Sudan".

Government negotiator Nhial Deng Nhial said the negotiations were "not easy".

"We hope to be able to make haste towards an agreement that will end bloodshed," he said.

"What worries us is whether the agreement on the cessation of hostilities will stick (and) the capacity of the rebel group ... to stop fighting.

"We would like to take this opportunity to urge the rebel group to heed the voice of reason and abandon the quest for political power through violence."

The world's newest nation has been at war since 15 December, with thousands killed, close to 500,000 forced to flee their homes and atrocities allegedly committed by both sides.