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, Khan’s lawyer, says the court made the decision on Friday, a day after the country’s Supreme Court called for a ruling. He says that Khan is now «a free man» and that the decision was fair.

The ruling came after Khan returned to court to hear whether he will be shielded from further arrest or taken back into custody, a decision that has unnerved the government and legions of Khan’s supporters after days of violent clashes.

The popular 70-year-old opposition leader appeared before the same court from which he was dragged and arrested on Tuesday. The arrest sparked nationwide protests in which his supporters attacked military installations, burned vehicles and ambulances, and looted general stores in various parts of the country. The government responded with strong measures, arresting almost 3,000 people.

Friday’s court session is part of a series of complex legal maneuvers.

On Thursday, Pakistan’s Supreme Court declared Khan’s arrest unlawful but then asked the Islamabad High Court, a lower court, to reconsider its initial decision to uphold the arrest.

The Supreme Court said it would abide by what the Islamabad court ruled on Friday.

In a brief opening session of the Islamabad court on Friday, the judges heard a request from Khan seeking protection from arrest on the corruption charges. As Khan’s supporters chanted in the courtroom, the judge adjourned for two hours. Outside, other supporters set fire to a police vehicle when security forces prevented them from approaching the court building.

Khan’s supporters celebrated after his release was ordered on Thursday.Anjum Naveed/AP

The government has said it would promptly re-arrest Khan if the Islamabad High Court upholds its earlier ruling that the initial arrest was lawful. It could also detain him on other charges if he is granted protection in corruption cases, the Interior Ministry said on Thursday.

The government maintains that Khan’s release rewards and encourages mob violence. In court on Friday, Khan’s top lawyer, Babar Awan, told reporters the government seemed adamant about arresting the former prime minister.

Khan’s arrest on Tuesday was a surprising and controversial move: National Accountability Office agents stormed the Islamabad High Court, where Khan was attending a session on other charges, dragging him away and putting him in an armored vehicle. The Supreme Court ruled that the arrest was «invalid and unlawful» because it took place from the court premises, violating Khan’s right to justice.

The ensuing violence left at least 10 Khan supporters dead. Dozens of protesters and more than 200 police officers were injured. Protesters set trucks, cars and police vehicles on fire and blocked roads. Nearly 3,000 supporters of Khan’s Pakistan Tehreek-e-Insaf party have been arrested, including Khan’s deputies.

Khan’s supporters turned to violence again on Friday, torching a police vehicle not far from the court where he was appearing. The police prevented them from getting near the court.

The controversy surrounding 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 riots have echoed those that followed the 2007 assassination of former Prime Minister Benazir Bhutto during an election rally. Her supporters at the time, outraged by her assassination, rampaged for days across Pakistan.

Khan, a former cricket star turned Islamist politician, was ousted as prime minister last year by a vote of no confidence in parliament and now leads the opposition. She faces more than 100 legal cases, most involving allegations that she incited violence and threatened police officers and government officials.

He also faces at least three corruption cases, including accusations by the National Accountability Office that he accepted millions of dollars worth of property in exchange for providing benefits to a real estate mogul. A new terrorism charge was filed against him on Thursday for allegedly inciting his followers to violence after his arrest.

Following the Supreme Court’s release order on Thursday, Khan spent the night at a government guest house in Islamabad, where he met with family and friends.

Pakistani President Arif Alvi also met with him. Alvi has been trying to defuse tension between Khan and the government of Prime Minister Shahbaz Sharif to prevent an escalation.

Speaking at a special cabinet meeting on Friday to discuss the developments, Sharif criticized the Supreme Court ruling, saying there was a «genuine corruption case» against Khan, «but the judiciary has become a stone wall that protects him.»

As Sharif’s government grapples with political turmoil amid a worsening economic crisis, it is also facing attacks by militants. According to the Pakistani army, two soldiers were killed and three wounded on Friday when insurgents attacked a security post in the city of Muslim Bagh, in the southwestern province of Balochistan. He said two insurgents were also killed in the exchange of fire.