(CNN) -- Ali Abdullah Saleh clung to power in Yemen for 33 years, navigating -- and even channeling -- the country's complex tribal power structure.
Rebellions, droughts and crises came and went, but Saleh never did, deftly playing rivals off each other to rule his fractious land, an act he once called "dancing on the heads of snakes."
On Wednesday, the 69-year-old ruler signed an agreement in Saudi Arabia transferring executive powers to the country's vice president, Abdo Rabu Mansour Hadi.
Although he retains his title as president for up to 90 days, the agreement would appear to end Saleh's rule after more than three decades.
Born in 1942 in Bayt al-Ahmar to the country's powerful al-Hashid tribe, Saleh never finished elementary school. He joined the army of the former Kingdom of Yemen at 16, and five years later was commissioned a second lieutenant in the army of North Yemen.
In 1974, Saleh participated in a coup that put a military council in charge of the country, and four years later ascended to the presidency after the previous leader, Ahmed Hussein al-Ghashmi, was assassinated.
When North Yemen and South Yemen reunited in 1990, Saleh became president of the new country and remained in power for the next 21 years, playing tribal rivalries off one another and remaining an ally of the West despite the lingering presence of al Qaeda in the Arab Peninsula in Yemen.
Then came the Arab Spring.
Inspired by protests in Tunisia that forced the country's president, Zine al-Abidine Ben Ali, to relinquish power after 23 years, demonstrations spread across the Middle East and North Africa, eventually toppling the regimes of Egyptian President Hosni Mubarak and Libyan leader Moammar Gadhafi.
The protests spread to Yemen, too, with small demonstrations in January growing larger as the weeks went on. They culminated in mass protests calling for Saleh's resignation despite his promises first to reform the constitution and later assurances that he would step down in 2013 and would not try to transfer power to his son.
The protests continued into spring and summer, spreading across the country and often resulting in violent clashes with security forces. Hundreds of protesters died in brutal crackdowns that attracted worldwide attention.
Saleh had said since May that he would sign the agreement brokered by the Gulf Cooperation Council that calls for him to step down in exchange for immunity, but repeatedly he balked.
In June, Saleh's rule seemed to be at an end when he was injured in an assassination attempt at his palace mosque. He traveled to Saudi Arabia to seek medical treatment, leading some to speculate his regime was over.
But in September, to the surprise of many, he returned to take back the reins of power.
On Wednesday, as he has before, he appeared to reverse course, telling the television station France 24 that he had no more desire to stay in power.
"Whoever hangs onto power I think is crazy," he told the station.
But unlike previous meetings with the Gulf Cooperation Council, this time, Saleh traveled to Saudi Arabia to sign the deal.
If Saleh's rule is truly over, it's unclear what he will do next.
A presidential source said before the signing that Saleh will stay in Saudi Arabia. U.N. Secretary-General Ban Ki-moon said Saleh told him he will instead seek medical treatment in New York.
Another Yemeni government official said whatever happens is anyone's guess.
"Everything's unpredictable with Saleh," the official said.