Pakistan's former prime minister Imran Khan has apologised in court on Thursday in an attempt to stay out of jail and avoid contempt charges.

He apologised for his outburst against a female judge during a rally last month that was seen as a threat to the judiciary and judges in general.

The apology, an option envisaged under the Pakistani legal system, may allow Khan to stay out of jail and avoid contempt charges.

Khan, who was ousted in a no-confidence vote in April, has been campaigning for early elections and claims he was toppled under a US conspiracy.

The development comes days after Pakistani police were ordered by a judge to drop terrorism charges against Khan in a separate case over threats to the same judge and also to police. 

He apologised for his outburst against a female judge during a rally last month that was seen as a threat to the judiciary and judges in general
He apologised for his outburst against a female judge during a rally last month that was seen as a threat to the judiciary and judges in general© Provided by Daily Mail
 The apology, an option envisaged under the Pakistani legal system, may allow Khan to stay out of jail and avoid contempt charges.The apology, an option envisaged under the Pakistani legal system, may allow Khan to stay out of jail and avoid contempt charges.© Provided by Daily Mail

The legal cases followed a speech Khan gave in the capital, Islamabad, during which he vowed to bring a lawsuit against the Islamabad police chief and a judge for allowing police to question Shahbaz Gill, chief of staff at Khan's Tehreek-e-Insaf political party.

Khan made the controversial remarks after being told Gill had allegedly been tortured by police following his arrest on charges of inciting troops to mutiny.

During the August rally, Khan at one point directed his comments at Judge Zeba Chaudhry, saying: 'You also get ready for it, we will also take action against you.'

Khan, a former cricket star turned politician who became premier in 2018, is currently on bail, which shields him from arrest in several cases.

'I am ready to apologise ... if the court thinks that I have crossed a line,' Khan said as he appeared before the Islamabad High Court on Thursday. 

Khan, who was ousted in a no-confidence vote in April, has been campaigning for early elections and claims he was toppled under a US conspiracy
Khan, who was ousted in a no-confidence vote in April, has been campaigning for early elections and claims he was toppled under a US conspiracy© Provided by Daily Mail
 Pakistan's former Prime Minister Imran Khan, who is facing a contempt of court case, appeared at a court, in Islamabad, Pakistan September 22, 2022
Pakistan's former Prime Minister Imran Khan, who is facing a contempt of court case, appeared at a court, in Islamabad, Pakistan September 22, 2022© Provided by Daily Mail

'I assure the court that this won't happen again in the future,' he added.

Chief Justice Athar Minallah said Khan's gesture was appreciated but that the former prime minister needs to submit his apology in writing before October 3, at which point Minallah would review the text and decide whether to drop the contempt case.

Khan's lawyer, Faisal Chaudhry, who is not related to Judge Chaudhry, later told reporters Khan's apology would be submitted in writing to the court shortly.

Dozens of Khan's supporters had gathered outside the court building to cheer him on and hundreds of police were deployed to prevent violence and to keep the crowd from pushing its way into the court.

Since his ousting, Khan has alleged - without providing evidence - that Pakistan's powerful military took part in an alleged US plot to oust him.

Washington, and the government of Khan's successor, Prime Minister Shahbaz Sharif, have denied the allegation.

Mr Sharif has also rejected Khan's demand, saying elections will be held on time next year.

In recent weeks, authorities have levelled several cases against Khan - including one for defying a ban on rallies.