Pakistan's Supreme Court has granted bail to opposition leader Javed Hashmi, who was jailed for inciting mutiny in the army, forgery and defamation.
Javed Hashmi is campaigning for the return of civilian rule
The former acting president of a Pakistan Muslim League faction was sentenced to 23 years in jail in 2004.
Mr Hashmi was effectively serving at most seven years in jail as he was handed seven different prison terms running concurrently.
He was arrested in 2003 over a letter critical of President Pervez Musharraf.
Mr Hashmi's appeal against his sentence is yet to be taken up for hearing by the high court in Lahore.
But the country's Supreme Court, headed by Chief Justice Iftikar Chaudhry, acting on a separate review petition, granted Mr Hashmi bail saying that he had already served his sentence.
"If periodic remissions are counted, he has already served his entire sentence," Chief Justice Chaudhry said, while granting bail to Mr Hashmi.
"Even if remissions are not allowed to him, he has nearly served the sentence, counting the length of his imprisonment before and during the trial," he added.
Mr Hashmi is still behind held in a prison in Lahore.
He will be immediately freed if he obtains bail in another case pending against him for fighting with government officials, our correspondent says.
Mr Hashmi is the leader of the Alliance for the Restoration of Democracy, a body campaigning for the return of civilian rule after Gen Pervez Musharraf's seizure of power in 1999.
Pakistan's army has dominated the country's affairs
He is also former acting president of the PML-N, the Pakistan Muslim League faction still loyal to former Prime Minister Nawaz Sharif who was ousted in the coup.
Javed Hashmi was arrested after circulating a letter bearing a military letterhead which was purportedly written by disgruntled officers.
It called for an inquiry into alleged corruption in the army's senior ranks and demanded a judicial investigation into a Pakistani military operation in Indian-administered Kashmir in 1999.
The authorities claimed the letter, which was also highly critical of Gen Musharraf and his alliance with the United States, was a forgery.
Mr Hashmi's allies said they believed the letter was genuine and that the charges of forgery were politically motivated.
He was convicted at a trial behind closed doors in the city of Rawalpindi, near Islamabad.
Mr Hashmi's trial was widely criticised as "politically motivated" by observers and opposition groups.
The US and other foreign governments had expressed concerns over lack of transparency in the trial.