Pakistan has fired a senior judge who accused the country's powerful spy agency of manipulating elections in July.

Justice Shaukat Siddiqi was removed as judge of a high court in the capital, Islamabad, through an order issued overnight by the president of Pakistan, the Law Ministry announced on October 12.

The Supreme Judicial Council, a body that oversees complaints against judges, had recommended Siddiqi's removal after a secret trial for "defaming a state institution," the ministry said.

Siddiqi had accused the Pakistani Army's spy agency, Inter-Services Intelligence (ISI), of manipulating the elections that brought Prime Minister Imran Khan to power in July -- an accusation that was also made by Khan's opponents.

The judge's accusation, just days ahead of the polls, added to questions about the legitimacy of the elections that were raised by the party of former Prime Minister Nawaz Sharif, which lost power in the elections.

Siddiqi said the decision to remove him was not unexpected.

It is widely believed that Pakistan's military, which has ruled the country for almost half of its history, did not want Sharif to seek another term.

Sharif, who was once Pakistan's most popular politician and an advocate for civilian supremacy, was removed by the Supreme Court as prime minister on corruption charges emanating from a leak of financial data in 2016 known as the Panama Papers.

He was later arrested just days ahead of the elections, a move that is thought to have spoiled his party's quest for the victory.

The dismissed judge claimed that the ISI was involved in Sharif's arrest and had told the court not to release Sharif and his daughter, Maryam, until after the elections. They were released on bail last month.

Pakistan's military denies interfering in politics and judicial affairs.

Based on reporting by dpa and Reuters