SOME 22 years after Imran Khan founded Pakistan Tehreek-e-Insaf (PTI) to break open the country’s corrupt dynastic politics, the 65-year-old former cricket star was waiting, as The Economist went to press, for official confirmation that his party had won the most seats in Pakistan’s general election. Projections suggested a tally of around 120 seats: short of a majority of the 272 elected seats in the lower house, but enough to form a ruling coalition with independent MPs rather than having to haggle with a serious rival party. Mr Khan looks to be the next prime minister. But his victory is far from sportsmanlike, in as tainted and perilously disputed an election as this one.

The doubts were long there. The outgoing majority party, the Pakistan Muslim League-Nawaz (PML-N), had warned that the army was “engineering” a victory for Mr Khan. The claim was echoed by civil-rights groups, the press and rival parties. The visas of an EU election-monitoring team were mysteriously delayed. Yet few expected widespread ballot-fixing, as in the days when generals used to stuff ballot-boxes full as sandbags.

That now appears naive. The last general election, in 2013, was not free of allegations of foul play. But they were made by just one party, the disappointed PTI, and brushed off by international observers and a subsequent Supreme Court investigation. This time almost every party except Mr Khan’s raised accusations of vote-tampering. Groups as utterly opposed as Tehreek-e-Labbaik (a new hardline Islamist outfit) and the Pakistan Peoples Party (a secular group) claimed that security officials ordered their polling agents out of the voting stations before a final tally had been reached. The PML-N alleged particular abuse in constituencies where the race was tight. Shahbaz Sharif, who leads the party while his brother, Nawaz, a three-term former prime minister, watches from a prison cell on a disputed conviction for corruption, said his party “wholly rejects” the result. “Our democratic process has been pushed back by decades,” he claimed. A delay in results, blamed by the election commission on a software glitch, did not improve confidence in the result.

The cloud over the outcome may not dissipate soon. The PTI’s disappointed rivals could mirror Mr Khan’s own past example and take to the streets, as he did in a four-month protest following the last election. That protest, however, enjoyed the sympathy of the army, keen to clip the wings of the Sharif brothers. This time the soldiers have in their sights their ideal outcome: a pliable leader and a minority government that will not be too powerful.

Rival parties may be persuaded to desist, and a tenuous stability take hold. If so, Pakistan’s growing current-account crisis may look more manageable. A request before long for the biggest IMF bail-out in Pakistan’s history looks unavoidable. It will not be popular, and runs against Mr Khan’s promise to create an “Islamic welfare state”. Rather him, his rivals may think, to force through IMF demands for austerity, subsidy cuts and further devaluations to the Pakistani rupee. And while the PTI’s army-backed victory looks tainted, at least extreme religious parties which might have made common cause with Mr Khan look genuinely to have been trounced.