The 14-point deal, signed in the presidential palace in Khartoum on Sunday, provides for the reinstatement of Hamdok as prime minister, and the release of civilian leaders, state media reported.
Hamdok will form an independent cabinet of technocrats, said senior Sudanese mediator Fadlallah Burma Nasir.
A group of Sudanese mediators who have been locked in talks to mediate a deal since the outbreak of the crisis released a statement outlining the main points of the deal.
It includes the restoration of Hamdok as prime minister, the release of all detainees, and what it said was the resumption of the constitutional, legal and political consensus governing the transitional period.
The statement from the mediators said the deal was reached following an agreement among political factions, ex-rebel groups, and military figures.
More protests as ‘opposition does not recognise the deal’
Sudan’s main civilian opposition coalition, the Forces of Freedom and Change, said on Sunday it does not recognise any political agreement with the military.
The coalition said mass protests rejecting the military’s power grab last month will continue.
Sudanese security forces fired tear gas to disperse protesters marching towards the presidential palace in Khartoum on Sunday.
Hundreds of Sudanese anti-coup demonstrators rallied on Saturday to denounce a deadly crackdown which medics say has left 40 people dead since the military takeover. Wednesday was the deadliest day with 16 people killed.
The agreement comes more than three weeks since General Abdel Fattah al Burhan derailed Sudan’s transition towards civilian rule with a military coup.
The military dissolved Hamdok’s cabinet and detained a number of civilians who held top positions under a power-sharing deal agreed with the military following Bashir’s ouster.
Following the coup, Hamdok had demanded the release of all political detainees and a return to power sharing as a precondition for negotiating, according to sources close to him.
Western powers that had backed Sudan’s political transition condemned the takeover and suspended some economic assistance to Sudan.