In a big relief and a legal victory for Pakistan's former president Pervez Musharraf, a court on Monday annulled the death sentence handed to him.
The court ruled that the special court which had found him guilty of treason last year was unconstitutional, a government prosecutor said.
A High Court in the eastern city of Lahore ruled it "illegal" on Monday.
"The filing of the complaint, the constitution of the court, the selection of the prosecution team are illegal, declared to be illegal... And at the end of the day the full judgment has been set aside," the prosecutor representing the government, Ishtiaq A. Khan said.
"Yes, he is a free man. Right now there is no judgment against him any longer," Khan added.
Azhar Siddique, the lawyer of Pervez Musharraf, gestures along with team members outside the Lahore High Court building after a court decision on Monday. AFP
The original ruling had marked the first time a former leader of the armed forces had faced such a sentence for treason in Pakistan, where the military maintains strong influence and senior officers are often considered immune from prosecution.
It caused a wave of controversy, with Musharraf − exiled in Dubai − slamming it as a "vendetta" and the military expressing its disappointment.
Musharraf's lawyer, Azhar Siddique, also told media outside the court in Lahore that it has "nullified everything".
The prosecution now has the option to file a new case against Musharraf with the approval of the federal Cabinet.
The treason trial − which began in 2013 and is just one of several involving Musharraf − centred on his decision to suspend the constitution and impose emergency rule in 2007.
Musharraf first took power after ousting prime minister Nawaz Sharif in a bloodless coup in 1999.
A boy leans on a sign as he films the supporters of Pervez Musharraf, after a court sentenced the former military ruler to death, during a protest in Karachi. File / AP
A cigar-smoking, whisky-drinking moderate, the general became a key US ally in the "war on terror" after the Sept.11 attacks and escaped at least three Al Qaeda assassination attempts during his nine years in office.
His rule faced no serious challenges until he tried to sack the Supreme Court chief justice in March 2007, sparking nationwide protests and months of turmoil that led to the imposition of emergency rule.
After the December 2007 assassination of former prime minister Benazir Bhutto, the national mood plunged further and Musharraf was left increasingly isolated by the crushing losses suffered by his allies in February 2008 elections.
He finally resigned in August 2008 in the face of impeachment proceedings by the new governing coalition and went into exile.
Musharraf returned to Pakistan in 2013 in an attempt to contest elections, but was barred from taking part in the polls and from leaving the country as a barrage of legal cases mounted.
The travel ban against him was finally lifted in 2016, and he travelled abroad for medical treatment.
The treason case against him was first launched by his old foe Sharif in 2013.
It went on for years with repeated delays until last year's surprise announcement.
Agence France-Presse