A ceasefire between South Sudan’s warring parties will begin at midnight on Sunday, in the latest bid to end a devastating four year war.

Government and several armed groups signed a ceasefire deal on Thursday during peace negotiations in Addis Ababa, to begin from 00:01 hours (local time) on 24 December.

The agreement says all forces should “immediately freeze in their locations”, halt actions that could lead to confrontation and release political detainees, as well as abducted women and children.

Riek Machar, the former vice-president whose falling out with President Salva Kiir started the conflict in December 2013, has ordered his rebel forces to “cease all hostilities”.

In a statement released on Friday, he said all forces should “remain in their bases and to act only in self defence or against any aggression”.

South Sudan’s leaders fought for decades for independence, but, after achieving it in 2011, a power struggle between Kiir and Machar led to all-out civil war two years later.

A peace deal was signed in 2015, but it collapsed in July 2016 when fresh fighting in the capital Juba forced then first vice-president Machar into exile.

The opposition split, with Taban Deng taking over as first vice-president, while Machar’s faction returned to battling the government in the bush.

While the initial fighting pitted Kiir’s ethnic Dinka against Machar’s Nuer, the renewed violence has developed with new armed opposition groups forming.

Violence spread to the southern region of Equatoria, forcing more than a million South Sudanese to flock to neighbouring Uganda and the Democratic Republic of Congo in what has become the biggest refugee crisis on the continent.

The latest round of peace talks, which the United Nations described as a “last chance” for peace in the country was pushed by the regional IGAD bloc as a revitalisation of the 2015 deal.

In addition to Kiir’s government and Machar’s SPLM-IO, this round of peace talks also includes half a dozen armed opposition groups that have sprung up since July.

A permanent ceasefire is the first step in negotiations to include a “revised and realistic” timeline to holding elections.

The initial peace deal planned for elections in August 2018 – a date seen as unfeasible by many observers.