Sudan's ousted Prime Minister Abdalla Hamdok is to be reinstated, after being placed under house arrest during a military coup last month.
All political detainees will be released as part of a new agreement between the military, civilian leaders and ex-rebel groups, mediators said.
On 25 October, Sudan's military had declared a state of emergency and dissolved the civilian leadership.
It sparked weeks of mass protests in which at least 40 people have died.
The deal was reached late on Saturday night, and is to be signed into action on Sunday, the head of Sudan's Umma Party, Fadlallah Burma Nasir, confirmed.
Mr Hamdok has agreed to the terms so that further bloodshed can be avoided, Reuters news agency reports, citing a source close to him.
The group of mediators, which included academics, journalists and politicians, released a statement outlining the terms of the agreement.
In addition to announcing the PM's reinstatement and the release of detained cabinet members, it says the rules governing Sudan's transition towards democracy will be restored.
Sudan's military and the Forces for Freedom and Change (FFC), a loose coalition of civilian groups, have been in a fractious power-sharing arrangement since August 2019, after long-time leader Omar al-Bashir was overthrown amid mass protests.
That arrangement was thrown into crisis last month when military leader, Gen Abdel Fattah al-Burhan, dissolved the civilian arm of the government and arrested its leaders.
He had been due to step down as chairman of the governing Sovereign Council this month, when a civilian chosen by the FFC would become the head of state.
Gen Burhan insists the army's action was not a coup, but a move needed to prevent a civil war that was threatening to erupt because political groups had been inciting civilians against the security forces.
He had appointed himself as the head of a new ruling council, with military and ex-rebel leaders by his side.
Across many cities, including the capital, Khartoum, anti-coup protesters put up makeshift barricades and burned piles of tyres, angry that their already-fragile path to democracy had been hijacked. The army responded violently, and are accused of shooting protesters.
One faction of the FFC has rejected the new deal, which comes ahead of more planned rallies on Sunday that will reportedly still go ahead.
The international community condemned the coup and demanded the release of political prisoners. The World Bank froze its aid to Sudan, and the African Union (AU) suspended the country's membership of the bloc.