Rival groups in Yemen signed a UN-brokered peace deal on Sunday after Shiite rebels seized the government headquarters and the prime minister resigned in the face of raging violence.
"A national peace and partnership agreement based on the outcomes of the national dialogue conference was signed this evening at the presidential palace" in Sanaa, state news agency Saba reported.
President Abdrabuh Mansur Hadi, United Nations envoy Jamal Benomar and representatives of Yemen's political forces, including the Huthi rebels, attended the signing ceremony, it reported.
In a speech, Hadi said: "We have reached a final deal with which we can overcome this crisis."
Benomar said the agreement calls for the formation of a government of technocrats within one month.
Under the deal, Hadi will also appoint advisers from the Shiite Ansarullah rebels and southern separatists within three days, Benomar said at the signing ceremony broadcast on state television.
The rebels earlier Sunday swooped on key institutions across Sanaa, including the government headquarters and military sites, after an apparent surrender by security forces.
And Prime Minister Mohamed Basindawa resigned, accusing Hadi of being "autocratic", according to the text of his resignation letter released by the council of ministers.
"The partnership between myself and the president in leading the country only lasted for a short period, before it was replaced by autocracy to the extent that the government and I no longer knew anything about the military and security situation," he wrote.
In a sign of the confusion sweeping Sanaa, Saba quoted a presidency source as saying Hadi had not received the letter, "therefore the government remains headed by Mohamed Salem Basindawa".
The rebels also overran state radio, the general command of the armed forces, headquarters of the sixth military region, the fourth brigade and the defence ministry's media arm, official and rebel sources said.
They swept into the parliament building and took over the central bank and civil aviation authority, the sources said.
The interior ministry's website urged security forces not to confront the insurgents.
Interior Minister Abdo al-Tarib instead urged "cooperation" with the rebels "to strengthen security and stability, preserve public property and guard government installations... and to consider Ansarullah friends of the police."
The rebels advanced into Sanaa from their mountain stronghold in the far north last month and set up armed protest camps to press their demands for political change.
Hadi on Friday denounced the Ansarullah offensive as a "coup attempt".
Sunday's developments came after a UN announcement Saturday of a power-sharing deal to end days of fighting between the rebels and army-backed Sunni militiamen belonging to the influential Al-Islah (Reform) Party.
Earlier Sunday, shelling and gunfire rocked northern Sanaa, prompting an exodus of terrified residents, an AFP correspondent reported.
A week of fighting has killed dozens on both sides and forced the suspension of all flights into and out of Sanaa airport.
The latest clashes centred on the campus of Al-Iman University, a bastion of Sunni Islamists that the Shiite rebels had been trying to capture, witnesses said.
Late Sunday, Saba reported that Hadi was meeting his advisers and Yemeni political forces, including representatives of Ansarullah.
He had already agreed to bring the rebels into a new government to replace the unpopular administration that imposed austerity measures, including a fuel price hike, earlier this year.
The rebels have demanded posts in key state institutions as part of their push for greater political clout.
With residents of northern districts fleeing their homes, the streets were largely deserted Sunday as shops remained closed and the education ministry ordered schools to suspend lessons.
Yemen has been swept by political turmoil since longtime strongman Ali Abdullah Saleh was forced from the presidency in early 2012.
The rebels hail from the Zaidi Shiite community, that makes up 30 percent of Yemen's mostly Sunni nation but the majority community in the northern highlands, including the Sanaa region.
They have battled the government on and off for a decade from their stronghold of Saada in the far north.