Pakistan's former Prime Minister Imran Khan speaks at an anti-government  rally in Islamabad on August 20.
Islamabad CNN  — 

Pakistan’s former Prime Minister Imran Khan was granted an extension of his pre-arrest bail on Thursday while police investigate whether he violated anti-terror laws.

The news was celebrated by hundreds of Khan’s supporters, who rallied outside the Anti-Terrorism Court in the capital, Islamabad, where the ousted leader’s arrival was met with a heavy security presence.

The court extended Khan’s pre-arrest bail until September 1, which means he cannot be arrested before then.

Police opened an investigation into Khan this week after he vowed to “take action” against the head of police and a magistrate during a speech in the capital on Saturday.

“Listen Director Inspector General (of police), we’re not going to let you go, we’re going to file a case against you. And madam magistrate you should also get ready, we will take action against you,” Khan had told his supporters during a rally in support of his former chief of staff, Shahbaz Gill.

Gill was arrested earlier this month on sedition charges after he urged soldiers to disobey orders from military leaders.

Khan has alleged police tortured Gill while in custody and the claims have gained traction among his supporters. Islamabad police deny Khan’s allegations.

Tensions between Khan and the ruling coalition government led by Prime Minister Shehbaz Sharif have simmered since the former star cricketer was ousted in a parliamentary no-confidence vote in April.

Khan has claimed there is a US-led conspiracy against him, accusing Sharif and the Pakistani military of working with Washington to topple his government. The United States, Sharif and the Pakistani military have all denied the allegations.

But Khan’s claims have struck a chord with a young population in a country where anti-American sentiment is common and anger at the establishment is being fueled by a rising cost-of-living crisis.

His enduring popularity has translated to recent provincial election victories for his party and he has repeatedly called for a new parliamentary vote at mass rallies held since his ouster.