Pakistan’s former president General Pervez Musharraf has died at the age of 79, an official has said.

He was the military ruler who seized power in a bloodless coup and later led a reluctant Pakistan into aiding the US war in Afghanistan against the same Taliban fighters his nation murkily backed even as Islamic militants twice targeted him for assassination.

Gen Musharraf, a former special forces commando, became president through the last of a string of military coups that hit Pakistan after its founding amid the bloody 1947 partition of India.

He ruled the nuclear-armed state after his 1999 coup through tensions with India, an atomic proliferation scandal and an Islamic extremist insurgency.

Former Pakistan President Pervez MusharrafFormer Pakistan president Pervez Musharraf in London (Ian Nicholson/PA)

He stepped down in 2008 while facing possible impeachment.

Later in life, Gen Musharraf lived in self-imposed exile in Dubai to avoid criminal charges, despite attempting a political comeback in 2012.

His family announced last June that he had been in hospital for weeks while suffering from amyloidosis, an incurable condition that sees proteins build up in the body’s organs.

Shazia Siraj, a spokeswoman for the Pakistani consulate in Dubai, confirmed his death and said diplomats were providing support to his family.

“I have confronted death and defied it several times in the past because destiny and fate have always smiled on me,” Gen Musharraf once wrote. “I only pray that I have more than the proverbial nine lives of a cat.”

Current Pakistani Prime Minister Shahbaz Sharif offered his condolences in a short statement, saying: “May God give his family the courage to bear this loss.”

Pakistan, a nation which is now home to 220 million people, drew US attention a little under two years after he seized power due to its border with Afghanistan.

Al Qaida leader Osama bin Laden launched the September 11 2001 attacks in 2001 from Afghanistan, sheltered by the country’s Taliban rulers, and Gen Musharraf knew what would come next.

“America was sure to react violently, like a wounded bear,” he wrote in his autobiography. “If the perpetrator turned out to be al Qaida, then that wounded bear would come charging straight toward us.”

By September 12, then-US secretary of state Colin Powell told Gen Musharraf that Pakistan would either be “with us or against us”. Gen Musharraf said another American official threatened to bomb Pakistan “back into the Stone Age” if it chose the latter.

Gen Musharraf chose the former. A month later, he stood by then-president George W Bush at the Waldorf Astoria in New York to declare Pakistan’s unwavering support to fight with the US against “terrorism in all its forms wherever it exists”.

Pakistan Obit Pervez MusharrafGeorge Bush with Pervez Musharraf at a news conference on November 10 2001 (Ed Bailey/AP)

Pakistan became a crucial transit point for Nato supplies heading to landlocked Afghanistan – even though Pakistan’s powerful Inter-Services Intelligence (ISI) agency had backed the Taliban after they swept into power in Afghanistan in 1994. Before that, the CIA and others funnelled money and arms through the ISI to Islamic fighters battling the 1980s Soviet occupation of Afghanistan.

The US-led invasion of Afghanistan saw Taliban fighters flee over the border into Pakistan, including bin Laden, whom the US killed in 2011 at a compound in Abbottabad. They regrouped and the offshoot Pakistani Taliban emerged, beginning a years-long insurgency in the mountainous border region between Afghanistan and Pakistan.

The CIA began flying armed drones from Pakistan with Gen Musharraf’s blessing, using an air strip built by the founding president of the United Arab Emirates for falconing in Pakistan’s Balochistan province.

The programme helped beat back the militants but saw more than 400 strikes in Pakistan alone kill at least 2,366 people, including 245 civilians, according to the Washington-based New America Foundation think tank.

Though Pakistan under Gen Musharraf launched these operations, the militants still thrived as billions of American dollars flowed into the nation. That led to suspicion that still plagues the US relationship with Pakistan.

Militants tried to assassinate Gen Musharraf twice in 2003 by targeting his convoy, first with a bomb planted on a bridge and then with car bombs.

The second attack saw his vehicle lifted into the air by the blast before hitting the ground again. It raced to safety on its rims, with Gen Musharraf pulling a pistol in case he needed to fight his way out.

It was not until his wife Sehba saw the car covered in gore that the scale of the attack dawned on him.

“She is always calm in the face of danger,” he recounted, but then, “she was screaming uncontrollably, hysterically”.

Pakistan Obit Pervez MusharrafUS secretary of state Colin Powell gives a news conference in Islamabad with General Pervez Musharraf in October 2001 (John McConnico/AP)

Born on August 11 1943 in New Delhi, India, Pervez Musharraf was the middle son of a diplomat.

His family joined millions of other Muslims in fleeing westward when predominantly Hindu India and Islamic Pakistan split during independence from Britain in 1947. The partition saw hundreds of thousands of people killed in riots and fighting.

He entered the Pakistani army at 18 and made his career there as Islamabad fought three wars against India. He launched his own attempt at seizing territory in the disputed Himalayan region of Kashmir in 1999 just before seizing power from prime minister Nawaz Sharif.

Mr Sharif had ordered Gen Musharraf’s dismissal as the army chief flew home from a visit to Sri Lanka and denied his plane landing rights in Pakistan, even as it ran low on fuel.

On the ground, the army seized control and after he landed Gen Musharraf took charge.

But as ruler, he nearly reached a deal with India on Kashmir, according to US diplomats at the time. He also worked toward a rapprochement with Pakistan’s long-time rival.

A major scandal emerged under his rule when the world discovered that famed Pakistani nuclear scientist AQ Khan, long associated with the country’s atomic bomb, had been selling centrifuge designs and other secrets to countries including Iran, Libya and North Korea, making tens of millions of dollars.

Those designs helped Pyongyang to arm itself with a nuclear weapon, while centrifuges from Mr Khan’s designs still spin in Iran amid the collapse of Tehran’s nuclear deal with world powers.

Gen Musharraf said he suspected Mr Khan but it was not until 2003 when then-CIA director George Tenet showed him detailed plans for a Pakistani centrifuge that the scientist had been selling that he realised the severity of what had happened.

Mr Khan confessed on state television in 2004 and Gen Musharraf pardoned him, although he was confined to house arrest.

Pakistan Obit Pervez MusharrafGeneral Pervez Musharraf addresses the UN General Assembly on November 10 2001 (Beth Keiser/AP)

Gen Musharraf’s domestic support eventually eroded. He held flawed elections in late 2002 — only after changing the constitution to give himself sweeping powers to sack the prime minister and parliament. He then reneged on a promise to stand down as army chief by the end of 2004.

Militant anger towards him increased in 2007 when he ordered a raid against the Red Mosque in central Islamabad, which had become a sanctuary for militants opposed to Pakistan’s support of the Afghan war. The week-long operation killed more than 100 people.

The incident severely damaged Gen Musharraf’s reputation among everyday citizens and earned him the undying hatred of militants who launched a series of punishing attacks.

Fearing the judiciary would block his continued rule, Gen Musharraf fired the chief justice of Pakistan’s Supreme Court, triggering mass demonstrations.

Under pressure at home and abroad to restore civilian rule, he stepped down as army chief.

He won another five-year presidential term, but he faced a major crisis after Benazir Bhutto’s assassination in December 2007 at a campaign rally as she sought to become prime minister for the third time.

The public suspected Gen Musharraf’s hand in the killing, which he denied. A later United Nations report acknowledged the Pakistani Taliban were a main suspect but warned that elements of Pakistan’s intelligence services may have been involved.

Gen Musharraf resigned as president in August 2008 after ruling coalition officials threatened to have him impeached for imposing emergency rule and firing judges.

“I hope the nation and the people will forgive my mistakes,” he said in an hour-long televised address.

Tony Blair visits Pakistan – day twoTony Blair is greeted by Gen Pervez Musharraf ahead of a meeting in Lahore (Stefan Rousseau/PA)

Afterwards, he lived abroad in Dubai and London, attempting a political comeback in 2012, but Pakistan instead arrested the former general and put him under house arrest.

He faced treason allegations over the Supreme Court debacle and other charges stemming from the Red Mosque raid and Ms Bhutto’s assassination.

The image of him being treated as a criminal suspect shocked Pakistan, where military generals have long been considered above the law. Pakistan allowed him to leave the country on bail to Dubai in 2016 for medical treatment and he remained there after facing a later-overturned death sentence.