For 33 years Ali Abdullah Saleh ruled Yemen with an iron grip. Skilled at weaving useful alliances and calculating risks, he was a master of the political game. But on Monday his luck ran out at the hands of the Houthi rebels who, until only days, ago, were his comrades in arms.
The 75-year-old was killed in an attack on his convoy. For several hours it was not known whether he had survived or not, even after grisly video footage appeared on social media showing his apparently lifeless body being bundled on to a flatbed lorry. But eventually, officials from his party, the General People's Congress (GPC) confirmed their leader was dead.
He was born on March 21, 1942 into a North Yemen family linked to the powerful Hashid tribal confederation. He had a limited education and in 1958 joined the army as a non-commissioned officer, and in 1962 took part in the coup that ended the rule of the imams and turned North Yemen into an Arab republic with the name of Yemen Arab Republic.
His big political break came when President Ahmed Al Ghashmi — who was also from the Hashid tribe, appointed Saleh military governor of Taez, North Yemen's second city. In 1978, Ghashmi was killed by a bomb. Saleh replaced him.
Overcoming entrenched tribal rivalries, he unified North and communist-ruled South Yemen by force and on May 22, 1990 was sworn in as president of a united country.
His regime did little to ease living standards in Yemen, still the poorest Arab nation today, yet Saleh managed to keep Western and Arab powers on his side, styling himself as a key ally of the United States in its war on terrorism while enriching his own family with the tens of millions of dollars in American military aid that flowed to units commanded by his relatives.
But he angered Gulf Arab allies by staying close to Saddam Hussein during the 1990-91 Iraqi occupation of Kuwait, leading to the expulsion of up to a million Yemenis from Saudi Arabia.
After the September 11 attacks in 2001, Yemen came on to Washington's radar as a source of foot soldiers for Osama bin Laden's Al Qaeda network. Though born in Saudi Arabia, bin Laden was Yemeni by descent. His family came from Yemen's Hadramawt region.
Saleh co-operated as the CIA stepped up a campaign of drone strikes against key Al Qaeda figures, which also led to scores of civilian deaths.
In 2011, Saleh survived a bomb attack on the mosque in his presidential compound which killed several of his senior aides and left him disfigured. Yet while other leaders were toppled or killed following the uprisings of what became known as the Arab Spring, Saleh seemed indestructible as he continued playing his enemies off each other as Yemen descended into tribal warfare and Islamist insurgency.
In 2012, after months of demonstrations against his regime he finally agreed to step down, ceding the presidency to his deputy, Abdrabu Mansur Hadi. But during the televised resignation ceremony on February 27, he wore a cryptic smile, suggesting that in his own eyes, at least, Saleh was far from finished.
Having won immunity from prosecution in exchange for leaving office, former president Saleh ostensibly retired to his villa in Sanaa to live quietly and contemplate his legacy. In 2013, he opened a museum documenting his 33-year rule. One of the exhibits was the burnt pair of trousers he was wearing during the 2011 assassination attempt.
In reality, however, he was plotting a comeback. Ultimately, that vainglory led his country to another war and to almost total collapse.
While president, Saleh had waged six wars against the Houthis — who like him belong to the Zaidi Shiite Muslim minority — from 2002 to 2009. In 2014, he joined forces with them after the Houthis seized Sanaa and then Aden, Yemen's main port and second city — and former capital of South Yemen — on the south coast.
It was a turbulent marriage. The two sides feuded for years for supremacy over territory which they ostensibly controlled together. The fact that Saleh loyalists killed the founder of the Houthi movement — and brother of their current leader — only deepened a mistrust that could never be set aside.
Alarm spread through the Arab world as it became incontrovertibly obvious that Iran was arming the Houithis and using them as proxies and at terrible cost to the Yemeni people.
In 2015, a military coalition led by Saudi Arabia and the UAE responded to a call for help from the internationally-recognised government of President Hadi.
Meanwhile, Saleh's forces and the Houthis continued sniping at each other over which was to blame for the collapse of the economy in the northern territories they controlled. On Wednesday last week it came to a head when they began fighting each other and the streets of Sanaa erupted into gun battles. Four days later, Saleh went on television to declare his alliance with the Houthis was over and he was now ready to talk to the coalition.
It was a gamble too far. Saleh was fond of likening Yemeni politics to "dancing on the heads of snakes." On Monday, one of the snakes reared up and bit him.