ISLAMABAD: Pakistan faced further chaos on Thursday when its top court ruled that the arrest of former Prime Minister Imran Khan was illegal, and ordered his immediate release.

Imran was detained on Tuesday by paramilitary Rangers troops on the orders of the anti-corruption National Accountability Bureau, which is investigating him and his wife in a case involving a land bribe.

His arrest sparked two days of protests in which at least six people were killed. Supporters blocked roads, torched trucks and cars, clashed with police and ransacked government buildings, including military property. Authorities arrested almost 3,000 people.

The government called in the army to Islamabad and the provinces of Punjab and Khyber Pakhtunkhwa to maintain order.

Imran’s Pakistan Tehreek-e-Insaf party challenged his arrest at the Supreme Court, and a three-member bench led by Chief Justice Umar Ata Bandial agreed. The arrest inside the Islamabad High Court had “violated the sanctity” of the judiciary, the judge said.

Imran was released from custody but will remain under the protection of security forces at a safe location in Islamabad. He is due to appear again before the Islamabad High Court on Friday.

After Imran’s release his supporters poured on to the streets of Islamabad to celebrate, and there were fresh clashes and tear gas shelling. Police on Thursday filed new terrorism accusations against Imran on charges of inciting mobs to violence.

Over 100 cases have been registered against Imran since he was removed as prime minister in April last year after losing a parliamentary confidence vote. He says the cases are politically motivated.

Imran’s party welcomed his release on Thursday and said it would “decide the next political course of action after consultation.” It said: “Pakistan Tehreek-e-Insaf believes in peaceful political struggle,” adding that it hoped “all institutions will strictly follow the orders of the Supreme Court.”