SANAA (Reuters) - Yemeni President Ali Abdullah Saleh has had to be a tough survivor to last 32 years as leader of an unruly and poor country that has witnessed civil war, uprisings and militant campaigns under his watch.
He once described running the fractious mountainous country of 23 million at the tip of the Arabian Peninsula as like "dancing on the heads of snakes"; but with opposition to his rule mounting from all corners over the past year, his dancing and juggling days appeared to be almost over.
Last year supporters were pushing for constitutional changes to allow Saleh unlimited five-year terms as president and speculation was high in the impoverished country that he was grooming one of his sons as a possible successor.
But it was a popular uprising that gathered pace in distant Tunisia in December that came to scupper the plans, which Saleh's Western and Arab backers had been expected to endorse, given their fears of the growing al Qaeda threat in Yemen.
After Tunisian President Zine al-Abidine Ben Ali fled on January 14, Egyptians began their own uprising that led to Hosni Mubarak's resignation as president on February 11.
By then, tens of thousands of Yemenis had began a daily protest outside Sanaa University and Saleh had begun to offer verbal concessions.
First he said he would not stand for re-election in 2013 and dismissed the idea of his son succeeding.
In March, when the opposition had gathered more momentum, winning the backing of tribal leaders, Saleh offered a referendum on a new constitution by the end of the year and a shift to a truly democratic "parliamentary system."
He continued to reject the street calls for a handover of power this year.
But the death of 52 protesters, mostly hit by sniper fire in Sanaa, on March 18 proved to be a turning point, prompting a string of key generals, tribal leaders, diplomats and ministers to resign or state their public allegiance to the protesters.
Many were from the al-Ahmar and Sanhan tribes, kinsmen who Saleh placed in key military and other positions, harming state building in a tribal society and stirring resentment among ordinary people in one of the world's poorest nations.
Saleh himself appeared to realize the gravity of the bloodshed, sacking his cabinet and declaring a 30-day state of emergency in the immediate days that followed.
Opponents often complained that Yemen under Saleh failed to meet the basic needs of the country's 23 million people. Unemployment reached around 35 percent and 50 percent for young people. Oil wealth is dwindling and water is running out, though liquid natural gas exports began in 2009.
Yet Saleh managed to keep Western and Arab powers on side.
After the September 11 attacks against U.S. cities in 2001, Yemen was on Washington's radar as a source of foot soldiers for Osama bin Laden's al Qaeda network. Bin Laden himself, though born in Saudi Arabia, originated from Yemen's Hadramaut region.
Saleh cooperated with U.S. 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 U.S. targets beyond Yemeni soil, as well as targeting foreign tourists at home. At the same time, northern Shi'ites rebelled against Saleh's rule and southerners, feeling marginalized, began a new separatist drive.
Again Saudi Arabia, the United States and other countries stepped up with financial support to bolster Saleh's rule.
If Saleh has been a wily survivor, he has also been a charismatic and often popular ruler who understood well the workings of Yemeni society.
Born in 1942 near Sanaa, he received only limited education before taking up a military career, beginning as a non-commissioned officer.
His first break came when President Ahmed al-Ghashmi, who came from the same Hashed tribe as Saleh, appointed him military governor of Taiz, North Yemen's second city. When Ghashmi was killed by a bomb in 1978, Saleh replaced him.
In 1990 an array of domestic and regional circumstances propelled North Yemen under Saleh and the socialist South Yemen state into a unification that Saudi Arabia at first opposed.
He angered Saudi Arabia for having been seen as backing Saddam Hussein during the 1990-1 Iraqi occupation of Kuwait, leading to the expulsion of up to 1 million Yemenis from Saudi Arabia. Before the crisis, Kuwait had given Yemen financial aid.
But Saleh then won plaudits from Western powers for carrying out economic reforms drawn up by the International Monetary Fund and World Bank, and made efforts to attract foreign investors.
He swept to victory when southerners tried to secede from united Yemen in 1994 and since then had drawn closer and close to Saudi Arabia, which he allowed to spread the influence of its radical Wahhabi form of Sunni Islam.
Over the years the country has often been in the news for kidnappings of foreign tourists by disgruntled tribesman. But though this sometimes led to deaths, Saleh seemed to emerge unscathed as tourists told tales to media back home of the hospitality they saw as hostages in the wild hills of Yemen.
(Writing by Andrew Hammond; Editing by Jon Hemming)