After months of evasion, procrastination and defiance, Yemeni President Ali Abdullah Saleh had one more surprise up his sleeve: he signed a Gulf accord which, on paper at least, stripped him of his powers.
Yemenis now turn to just how the deal will be implemented to secure the dismantling of the rule of the 69-year-old whose iron grip enmeshed his family, friends and allies in the nation's military, business and economy.
Ten months of political strife have already loosened state control over much of Yemen, allowing free rein to northern rebels, southern secessionists and al Qaeda, even as drastic shortages of water, fuel and jobs stalk its 24 million people.
The convulsions in this fractured Arabian Peninsula state that borders oil giant Saudi Arabia, have brought the impoverished country to the brink of civil war, causing deep concern in Riyadh and Washington.
One of the main obstacles to implementing a deal, diplomats say, is Saleh himself, who once compared his own 33-year balancing act to retain power to dancing on the heads of snakes.
I fear there are so many gaps and that issues of implementation could spoil the whole thing, said Ghanem Nusseibeh, a UK-based analyst.
It is the best the Yemenis could expect.
Many diplomats warn the pact that Saleh signed to appease his opponents and the big powers contains flaws that could be exploited to undermine its implementation at every stage.
Saleh is a clever operator who has survived many tussles with rivals, and skilfully used patronage to keep tribal and political backers loyal.
Any hopes the deal might bring peace were rattled just one day after its signature with at least five Yemenis killed by gunmen believed to be Saleh loyalists who attacked a protest demanding Saleh face trial. The deal provides him with immunity.
There are also no signs of the thousands of protesters on Sanaa's streets leaving their tents that have become their homes for the past 10 months.
Many are still angry that the Gulf-brokered deal signed by Saleh guarantees him immunity, as well as his sons and nephew who have controlled a nation where about 42 percent live on less than $2 a day.
Diplomats say the accord was only signed after intense pressure by the United States, Saudi Arabia and European states on Saleh and on opposition parties to reach a deal.
They say that Washington was keen to wrap up the situation in Yemen in an orderly manner before a potential messy exit for Saleh that could affect its regional ally and the world's number one oil exporter, Saudi Arabia.
The United States is also keen to resolve the crisis in Yemen while it grapples with other regional challenges, especially in Syria and Egypt, the diplomats say.
Continued mayhem in Yemen, sitting along a vital shipping strait, also raises risks for world oil supplies.
Although the agreement accords Saleh a ceremonial position as head of state with no powers, he still holds sway over the armed forces and the economy.
Even if he heads to the United States after handing over power, as he had told U.N. Secretary-General Ban Ki-moon he would do to seek medical treatment, Saleh will remain leader of the long-ruling General People's Congress party.
The party will be a partner in the power-sharing government that will be set up with the opposition during an interim period ahead of a presidential election.
Apart from controlling the main branches of the security establishment, including the elite Republican Guards and domestic security services, Saleh's relatives also dominate the economy through public and private companies they run.
Under the accord, a military committee headed by the country's new ruler, Abd-Rabbu Mansour Hadi, a former army officer respected by the opposition, will oversee restructuring of the armed forces.
But analysts are sceptical that such a committee will be able to remove top commanders such as Saleh's son, Ahmed, commander of the Republican Guards regarded by the United States as a bulwark against al Qaeda.
Ahmed Saleh's presence at the helm of the Republican Guards is a continuation of the regime, said Ibrahim Sharqiyeh, an analyst at the Brookings Doha Center in Qatar.
Will the Republican Guards be ready to see Ahmed replaced? It remains to be seen.
Equally worrying to many is the fact that key players in the opposition, especially activists who had camped in downtown Sanaa and Taiz for months, are not happy with the accord that gives Saleh and close aides, including family members immunity.
We did not go out to the street and offer sacrifices so Saleh and his relatives are accorded immunity from legal pursuit, said Fayez Ahmed, a 26-year-old demonstrator who had been camping at Sanaa's Change Square for months. We want the killers to be tried.
Regional powerhouse Saudi Arabia, which has long bank-rolled Saleh and some of his tribal opponents, has staked its reputation on the agreement when King Abdullah oversaw the signing ceremony in his palace in Riyadh.
Saudi Arabia, which had endured three years of attacks by militants including veterans of the Afghan and Iraq wars on foreigners, security forces, members of the royal family and an oil facility, has worried that al Qaeda will exploit the chaos caused by protests to set roots in Yemen and recruit followers.
The group has seized control in parts of Abyan province, including the capital Zinjibar and the coastal city of Jaar, which is under complete control of militants allied to al Qaeda.
But analysts say the threat to the accord also comes from two other sworn enemies of Saleh -- a dissident general who broke away from the Yemeni army after the outbreak of the uprising in February and from the al-Ahmar tribal federation led by Sadeq al-Ahmar.
Reflecting the lack of trust that exists between Saleh and his opponents, Adel Amin wrote in a column posted on the opposition's sahwa website (sahwa-yemen.net) that the Yemeni president will find a way to spoil the accord.
He may offer objections to the proposed prime minister or could use the restructuring of the army and the security to obstruct the agreement, Amin wrote.
It cannot be ruled out that a man like Saleh, who has mastered deception ... comes back after the signing to put us in front of a new crisis of interpretations on how to implement the initiative and the steps to do that.
(Reporting by Sami Aboudi, editing by Peter Millership)