Former Prime Minister Imran Khan of Pakistan was sentenced to 10 years in prison on Tuesday, the latest twist in what is widely seen as a campaign by the military to sideline one of its leading critics from politics.

The sentence, which was delivered in a case in which Mr. Khan is accused of leaking state secrets, came about a week before Pakistan is set to head to the polls for the first national election since he was ousted in a vote of no confidence in April 2022.

Analysts have called the election among the least credible in Pakistan’s 76-year history because of the military’s widespread crackdown on Mr. Khan and his supporters.

His ouster set off a political showdown between Mr. Khan and the country’s powerful military, which has long been the invisible hand guiding the country’s politics. Mr. Khan and his supporters have accused military leaders of orchestrating his removal — an accusation they deny.

The country has been embroiled in the political crisis spawned by Mr. Khan’s ouster for a year and a half. As Mr. Khan and his supporters have railed against the country’s generals, public anger at the military has swelled. In May, hundreds of protesters attacked military installations in scenes that were once unimaginable in Pakistan.

In response, the military launched a widespread intimidation campaign aimed at weakening Mr. Khan’s political party, Pakistan Tehreek-e-Insaf, or P.T.I., and curbing the remarkable political comeback he has made even as he has been jailed and barred from contesting the national election next week.

The verdict on Tuesday was handed down by a special court that was established last year and that analysts say is more deferential to the military’s wishes. Mr. Khan has called the trial a “fixed match,” suggesting its outcome was predetermined, and his party said it would appeal the verdict.

“This 10-year sentence won’t stand for 10 days before the appellate courts. Such brazen disregard of law and constitution has never been witnessed before,” Taimur Malik, one of the lawyers for Mr. Khan, said in a post on X, formerly known as Twitter.

Shah Mahmood Qureshi, a former foreign minister and close aide to Mr. Khan, was also handed a 10-year sentence on Tuesday in the same case.

Salman Masood contributed reporting from Islamabad.