A high court in Islamabad has granted former prime minister Imran Khan a two-week reprieve from arrest in a corruption case and granted him bail on the charges.
Babar Awan, the lawyer for Mr Khan, says the court made the decision on Friday, a day after the country's Supreme Court ruled it "invalid and unlawful".
He said Mr Khan was now "a free man," and that the decision was fair and just.
The ruling came after Mr Khan returned to court to hear whether he would be shielded from renewed arrest or taken back into custody.
It is a decision that has put the government and legions of Khan supporters on edge after days of violent confrontations.
Nearly 2,000 people have been arrested for violence since Mr Khan's detention on Tuesday and at least eight have been killed.
The former World Cup-winning cricket captain arrived amid tight security at the court in Islamabad.
Friday's court session was part of a series of complex legal manoeuvres.
The government contends that Khan's release rewards and encourages mob violence.
In court on Friday, his lawyer Babar Awan told reporters that the government seemed to be adamant about arresting the former prime minister.
Mr Khan's arrest on Tuesday was a startling and controversial move.
Agents from the National Accountability Bureau burst into the Islamabad High Court where Khan was attending a session on other charges and dragged him away, putting him into an armoured vehicle.
The Supreme Court ruled that the arrest was "invalid and unlawful" because it took place from the court premises, violating Mr Khan's right to justice.
Mr Khan's supporters on Friday again resorted to violence, setting fire to a police vehicle not far from the court where he was appearing.
The police stopped them from approaching the court.
The controversy surrounding Mr Khan — a figure who inspires both vehement loyalty and furious opposition — threatens to open a deeper vein of turmoil in a country that has seen multiple military takeovers and bouts of violence.
The unrest has echoed that which followed the 2007 assassination of former prime minister Benazir Bhutto during an election rally.
Her supporters at the time, outraged by her killing, rampaged for days across Pakistan.
Mr Khan was removed as prime minister last year by a no-confidence vote in parliament and now leads the opposition.
He faces more than 100 legal cases, most involving allegations that he incited violence and threatened police and government officials.
Wires/ABC