The fortunes of Pervez Musharraf, Pakistan's most recent military ruler, have see-sawed in the last two decades.
After seizing power in a 1999 coup, he went on to survive numerous assassination attempts, and found himself on the front line of the struggle between militant Islamists and the West.
But by 2008, the career soldier had suffered defeat at the polls and was accused of unlawfully suspending the constitution to impose emergency rule.
And then, 20 years after his rise to power, he was sentenced to death in absentia after being found guilty of treason - only for it to be overturned less than a month later.
At a glance
1943Born in Delhi, India
1961Joins Pakistan Military Academy
1999Leads bloodless coup and becomes president two years later
2008Goes into self-imposed exile - returns from 2013 to 2016
2014Charged with high treason
Pervez Musharraf was born in Delhi on 11 August 1943 to Urdu-speaking parents who migrated to Pakistan after the partition of the Indian sub-continent in 1947.
After a long career in the military he became chief of staff in 1998 under then-prime minister Nawaz Sharif - before dramatically toppling his elected government the following year.
His appointment had been a gamble for Mr Sharif, who promoted him over the heads of more senior generals as he sought to exert control over the military.
Mr Sharif's own popularity was at the time plunging amid an economic slump and controversial reforms, as well as fallout over a crisis in Kashmir. Pakistan had been embarrassed by a failed attempt to seize territory in Kashmir that year, and the military were unwilling to take all the blame.
When Mr Sharif moved to replace Gen Musharraf, his army chief outmanoeuvred him, spotting his chance to seize power with the weight of the military behind him.
But his decision to support President George W Bush's "war on terror" in 2001, following the 11 September attacks, inevitably meant that he would end up clashing with militants sympathetic to both the Taliban - who Pakistan's army has long-been accused of links to - and al-Qaeda.
The president was often described as walking a tightrope as he sought to balance pressure from the US to crack down on extremism in Pakistan and the demands from an increasingly vocal and anti-American Islamist constituency.
Afghanistan also loomed large.
Mr Musharraf was frequently accused by Nato and the Afghan government of not doing enough to stem the movement of militants sympathetic to al-Qaeda and the Taliban from Pakistan's tribal areas into Afghanistan.
Pointed questions over his record re-surfaced in 2011 when Osama Bin Laden, the al-Qaeda leader, was found to have been living for years in Pakistan, not far from a military academy - something Gen Musharraf denied he knew.
Fall from power
Gen Musharraf's time in power was also marked by struggles with the judiciary, including protracted disputes over his oft-stated desire to remain head of the army while simultaneously being president.
In early 2007 he sacked chief justice Iftikhar Muhammad Chaudhry, sparking a country-wide protest movement.
Months later he ordered a bloody siege at Islamabad's Red Mosque with its adjacent Islamic school, resulting in the deaths of more than 100 people. Clerics and students of the mosque were accused of waging an increasingly aggressive campaign to enforce a strict interpretation of Sharia law in Pakistan's capital.
The outrage over that episode led to the creation of the Pakistani Taliban and a campaign of bombings and attacks that left thousands dead.
When Nawaz Sharif returned from exile in late 2007, it marked the beginning of the end of the Musharraf era.
The former general tried to extend his tenure by imposing emergency rule but in February 2008 his party lost parliamentary elections. Six months later, he resigned to avoid impeachment and then left the country.
Living in London and Dubai, the former president is believed to have earned hundreds of thousands of dollars on worldwide lecture tours. But he never made any secret that his main ambition was to return to power in his homeland.
In March 2013, he dramatically returned to Pakistan to compete in elections but it ended in humiliation and arrest. He was barred from standing and his All Pakistan Muslim League (APML) performed as badly as many had predicted.
He became quickly embroiled in a slew of court cases, including being accused of failing to provide adequate security for Benazir Bhutto, whose assassination by the Taliban in 2007 shocked Pakistan and the world. A 2010 United Nations inquiry into the murder had accused Gen Musharraf's government of "wilful failure" to protect the former prime minister.
The same year, he was accused of treason over his decision to suspend the constitution back in 2007.
But the trial was never going to be easy in a country where the military has ruled on and off since independence and continues to hold great sway. So the government decided to set up a special court to try the former military leader.
It took more than five years before the judges in the case handed down their shock ruling: Gen Musharraf was guilty, the three member bench said.
He was handed the death penalty.
And then, another surprise: less than a month after the sentence was delivered, the entire process was declared unconstitutional by Lahore's high court. The case, in theory, was right back at square one, the sentence overturned.
Not that it had been clear if it would ever be carried out. In 2016, after a travel ban was lifted for medical reasons, he again left the country and has been living in exile in Dubai ever since.