SANAA // Ali Abdullah Saleh once compared running Yemen to "dancing on the heads of snakes".
In 33 years he has led a poor, unruly and fractious nation through civil war, uprisings, militant campaigns, tribal feuds and poverty.
His dancing days are just about over after he finally stepped down yesterday instead of pirouetting away from the edge at the last minute as he did three times before.
The bombing of his presidential compound in June, an apparent assassination attempt, covered him with severe burns and drove him abroad to recover in exile in Saudi Arabia.
But Mr Saleh made his way back into the snakepit in September. His return to Sanaa created a spike in violence and moved the country closer to civil war.
Only recently, Mr Saleh's rule seemed all but unshakeable. Last year, supporters were pushing for constitutional changes to allow him an unlimited number of five-year terms as president. Speculation also suggested he was grooming one of his sons as a possible successor.
But the popular uprising that began in Tunisia in December came to scupper the plans. After the Tunisian president, Zine El Abidine Ben Ali, and Egypt's Hosni Mubarak fell from power, tens of thousands of Yemenis protested in the capital and Mr Saleh began to promise concessions.
First Mr Saleh said he would not stand for re-election in 2013 and dismissed the idea of his son succeeding him, then he offered a referendum on a new constitution by the end of the year and a shift to a truly democratic "parliamentary system".
But after the death of 52 protesters in March, a string of generals, tribal leaders, diplomats and ministers resigned or declared their public allegiance to the protesters.
Many were from the Al Ahmar and Sanhan tribes, kinsmen whom Mr Saleh had placed in key military and other positions.
Mr Saleh became the ruler of North Yemen in 1978 at a time when the south was a separate, communist state, and led the unified country since the two states merged in 1990.
Opponents often complained that Yemen under Mr Saleh failed to meet the basic needs of the country's people, with two out of every three living on less than US$2 (Dh7.34) per day. Oil wealth is dwindling and water is running out, though liquefied natural gas exports began in 2009.
Yet Mr Saleh managed to keep western and Arab powers on side. The United States has talked openly of its concern about who might succeed Mr Saleh, an ally in the fight against Al Qaeda in the Arabian Peninsula, a Yemen-based wing of the militant group.
After the September 11 attacks, Yemen came on to Washington's radar as a source of foot soldiers for Osama bin Laden's Al Qaeda network.
Mr Saleh co-operated with US authorities, and the CIA carried out a successful drone attack against a wanted figure. But by 2007, militants had regrouped in Yemen and in 2008 they announced that their Saudi and Yemeni wings had united under the banner of Al Qaeda in the Arabian Peninsula.
From 2009, the resurgent group made ever bolder attempts to stage attacks on Saudi and US targets beyond Yemeni soil, as well as targeting foreign tourists at home.
At the same time, northern Shiites rebelled against Mr Saleh's rule and southerners, feeling marginalised, began a new separatist drive.
Saudi Arabia, the US and other allies responded by stepping up with financial support to bolster Mr Saleh's rule.