Sudanese Prime Minister Abdalla Hamdok is to be reinstated – almost a month after being placed under house arrest in a military coup.
In addition, government officials and politicians who have been arrested since the takeover on 25 October are to be released.
A new cabinet, described as “technocratic” and led by Mr Hamdok, will make decisions until elections are held.
It is unclear how much power the new civilian government will have, however, because it will be subject to military oversight.
A 14-clause deal states that power should be handed over to an elected civilian government once a transitional period has ended.
The coup was launched more than two years after the removal of autocrat Omar al-Bashir, who ruled Sudan for 20 years.
It has now been ended two days after at least 15 people were killed by live fire during demonstrations against it.
Sudan: Three killed as security forces open fire during anti-coup protest
Sudan: Prime minister and wife at home “under heavy security” after military coup – as ministers reject takeover
Sudan: At least seven killed and 140 injured as troops open fire following coup
About 40 people have been killed by security forces during demonstrations in the last few weeks.
Mr Hamdok said he had agreed the deal to prevent any more loss of life.
“Sudanese blood is precious,” he said. “Let us stop the bloodshed and direct the youth’s energy into building and development.”
During a signing ceremony broadcast on state television, he added: “The signing of this deal opens the door wide enough to address all the challenges of the transitional period.”
Sudan’s top general, Abdel Fattah Burhan, said: “By signing this declaration, we could lay a genuine foundation to the transitional period.”
Opposition remains, however. The Forces for the Declaration of Freedom and Change (FFC), which spearheaded an uprising against al-Bashir, objected to a deal with the military, and said those behind the coup should be brought to justice.
The FFC had been sharing power with the military.
“We are not concerned with any agreements with this brute junta and we are employing all peaceful and creative methods to bring it down,” it said.
Ahead of the deal’s announcement, security forces fired tear gas to disperse protesters as they approached the presidential palace.
“Hamdok has sold the revolution,” some sang shortly after it was signed.