FILE - Protected by a bulletproof barrier, former Prime Minister Imran Khan speaks during a rally in Lahore, Pakistan, Sunday, March 26, 2023. [K.M. Chaudhry, AP Photo]

A high court in Islamabad on Friday granted former Prime Minister Imran Khan protection from arrest in a graft case and ordered him freed on bail.

The ruling came as the government and legions of Khan's supporters were on edge after days of violent confrontations sparked by the arrest of the former prime minister earlier this week. The government has vowed it will find a way to take Khan back into custody, a move that would likely cause a resurgence of riots and mob attacks.

Friday's ruling by the Islamabad High Court gave Khan protection from arrest on one of several corruption cases against him for a period of two weeks, a form of interim bail that usually is renewed in the Pakistan judicial system.

Khan, however, remained in the court after the decision as his lawyers petitioned the judges for similar protection in a number of other corruption charges, trying to close off a legal avenue for the government to arrest him again.

Khan's chief lawyer, Babar Awan, praised the ruling, and said Khan was now "a free man."

A short while later, the court said Khan could not be arrested for the time being in other pending corruption cases against him. The former premier was expected to walk out of the court shortly.

The government contends that Khan's release rewards and encourages mob violence. After he was arrested Tuesday, his supporters attacked military installations, burned vehicles, and ambulances and looted general stores in various parts of the country. The government responded with a crackdown, arresting nearly 3,000 people. The violence left at least 10 Khan supporters dead. Dozens of protesters and more than 200 police officers were injured.

The arrest 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 - the same court where he appeared Friday - and dragged him away, putting him into an armored vehicle.

On Thursday, Pakistan's Supreme Court ruled that arrest unlawful, but asked the Islamabad High Court, a lower court, to reconsider its initial decision to uphold the arrest.

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 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.

Khan, a former cricket star turned Islamist politician, 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.

He also faces at least three graft cases, including accusations from the National Accountability Bureau that he accepted millions of dollars worth of property in exchange for providing benefits to a real estate tycoon. 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 Thursday, Khan spent the night at a government guest house in Islamabad, where he met with family members and friends.

Pakistan's president, Arif Alvi, also had a meeting with him. Alvi has been trying to defuse tension between Khan and Prime Minister Shahbaz Sharif's government to avoid an escalation.

Speaking at a special Cabinet meeting 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 protecting him.

As Sharif's government contends with the political turmoil amid a worsening economic crisis, it is also dealing with militant attacks. According to Pakistan's military, two soldiers were killed and three were wounded Friday when insurgents attacked a security post in the town of Muslim Bagh in southwestern Baluchistan province. It said two insurgents were also killed in the exchange of fire.