The president latterly stressed his credentials as a civilian leader
Former Pakistani President Pervez Musharraf took power in a coup in 1999. One of Pakistan's longest-serving rulers, his time in power was characterised by dramatic upheavals.
The then Gen Musharraf ousted Prime Minister Nawaz Sharif promising to bring "true" democracy, law and order and economic revival to Pakistan.
The early part of his rule was also dominated by questions of foreign policy, particularly tensions with India over Kashmir.
Then came the events of 11 September 2001 that became the defining feature of his presidency, leading to a dramatic change in Pakistan's relations with the rest of the world. It became a country in the forefront of President George W Bush's "war on terror".
Such a course inevitably meant that President Musharraf would end up clashing with Islamic militants in his country sympathetic to the Taliban and al-Qaeda.
Perhaps the most powerful manifestation of this change of direction came in July 2007, when the president ordered his security forces to storm the Red Mosque with its adjacent Islamic school in Islamabad, resulting in the deaths of more than 100 people.
Born on 11 August 1943, Delhi, India
Married with two children
Joined Pakistan Military Academy in 1961
Saw action in the 1965 war against India
Attended Royal College of Defence Studies in the UK
Frequently promoted, was made a general in 1998
Clerics and students of the mosque were accused of waging an increasingly aggressive campaign to enforce strict Sharia law in Pakistan's capital.
In the weeks after the mosque was seized, clashes between soldiers and Islamic militants in the country's northern tribal regions escalated and suicide bombings - a rarity in Pakistan - became more commonplace.
President Musharraf was challenged by others too.
His decision to suspend the country's Chief Justice, Iftikhar Mohammad Chaudhry, in March 2007 backfired seriously and led to a major loss of his authority.
The move triggered huge protests across the length of the country against his perceived flouting of the rule of law.
Such was the level of dissent over the decision that the president was forced to back down and reinstate Mr Chaudhry in July 2007.
President Musharraf's oft-stated desire to remain head of the army while simultaneously being president of Pakistan was then challenged in the courts.
Although he was elected to a new term as president by the four provincial assemblies and both houses of parliament in October, the result was not validated by the Supreme Court.
Before the vote, the president's lawyers said he would stand down as army chief once re-elected. Pressure for him to give up the army post had been rising considerably.
On 3 November 2007, President Musharraf declared a state of emergency, removing many Supreme Court judges and going on to install hand-picked replacements in their stead.
All legal challenges to the president's eligibility in the October poll were subsequently dismissed and the reshaped Supreme Court ordered the Election Commission to declare him the winner.
The president has been a key US ally
President Musharraf went on to hand over command of the army to his personally anointed successor on 28 November 2007, the day before his new term was to start.
The turbulent events of 2007 were in contrast to the relatively smooth way in which the man who was shunned as a dictator by many in the West after his bloodless coup became, almost overnight, a pivotal player on the world stage as Washington realised it needed the co-operation of Pakistan in order to defeat the Taliban.
Pakistan had previously been one of only three countries to recognise the Taliban diplomatically and had been accused of playing a pivotal role in its early development.
The president was often described as walking a tightrope as he has sought to balance demands from the US to crack down on extremism in Pakistan and the demands from an increasingly vocal and anti-American Islamist constituency.
Tensions with nuclear rival India have lowered since the two countries began peace talks in early 2004.
Relations had worsened after an attack on the Indian parliament in Delhi in December 2001. India blamed terrorists sponsored by Pakistan - an allegation denied by Pakistan.
By the summer of 2002 the two countries appeared to be on the brink of war with over a million troops massed along both sides of the Line of Control that divides the disputed territory of Kashmir.
However, problems with neighbouring Afghanistan have got worse. Afghan officials - along with Nato - have increasingly accused Pakistan of not doing enough to stem the movement of militants sympathetic to al-Qaeda and the Taliban across the border into Afghanistan.
In another sign of growing uncertainty in the West over the Mr Musharraf's usefulness in the "war on terror", the policy of signing local peace agreements with militants in the north-west of the country has also been strongly criticised.
Pakistan counters that it has sent its troops into Waziristan and other tribal regions to target al-Qaeda and Taliban fighters for the first time in the country's history.
President Musharraf was also engaged on another front against nationalists in the province of Balochistan who accuse the government of exploiting the region's natural resources but neglecting its development.
Mr Musharraf had to cope with a humanitarian tragedy in October 2005 as a massive earthquake measuring 7.6 on the Richter scale hit Pakistan-administered Kashmir.
More than 73,000 people died and three million were made homeless as a result of the quake.
Turning around the decline in economic growth was part of President Musharraf's promise on assuming power.
Initially he oversaw an improvement in economic growth - receiving praise from international institutions for the introduction of reforms - but more recently the strength of the Pakistani economy has been called into question.
The former president's departure has not brought an end to the major problems facing the country, not least about how it is governed.
Another of Mr Musharraf's promises on assuming office was to devolve power to the grassroots and improve accountability.
The Delhi-born son of an Urdu-speaking family that migrated to Pakistan after the partition of the Indian sub-continent in 1947 has survived numerous assassination attempts and plots.
But he faced an increasing number of challenges on the domestic front - especially rising prices of fuel and food.
At the same time his one of main political enemies, Nawaz Sharif, returned to the country from exile to lobby strongly against him from November 2007 onwards. In the early years of Mr Musharraf's rule, such a development would have been unthinkable.
Sectarian violence between Sunni and Shia Muslims also simmers on.
President Musharraf relinquished power as Pakistan sits in the shadow of an increasingly blossoming relationship between the US and arch-rival India.
Its battle against militancy continues unabated.