Opposition parties rejected the outcome even before official results were in. What will Mr Khan do – and be able to do – with the victory he has just claimed?

Imran Khan says that he has won the election in Pakistan, and is poised to fulfil his long-pursued ambition to lead the country. Projections give his Pakistan Tehreek-e-Insaf party a commanding lead, but opponents of the cricket star turned populist politician are unanimous in rejecting the outcome. Though the startling delay in results and reports of ballot-stuffing fuelled suspicion and anger, there had already been warnings of the dirtiest election in recent history.

The army has directly ruled Pakistan for half of its 71-year history, wielding power behind the scenes in between. If all goes smoothly, this will be only the second time one civilian government has replaced another. Tens of millions went to the polls, despite deadly campaign violence including a suicide bombing on election day. While in places women were prevented from voting, in other areas women voted for the first time.

But even before the problems with casting and counting votes, Pakistan’s Independent Human Rights Commission had warned of “blatant, aggressive and unabashed attempts to manipulate” the outcome, mostly through intense pressure on the media and the intimidation of candidates. While the military denies it has intervened in favour of Mr Khan, no one doubted its determination to see off the incumbent Pakistan Muslim League-Nawaz. Though the jailing of its leader Nawaz Sharif followed revelations in the Panama Papers, his supporters were not alone in seeing selective prosecution or suggesting that his greater offence was pushing back against the military.

But Mr Khan has also benefited from voters’ frustration with years of corruption and dynastic politics dominated by the PML-N and the Pakistan Peoples party (now headed by Bilawal Bhutto Zardari, son of the assassinated Benazir Bhutto, the PPP seems to be positioning itself for the next contest). Mr Khan promises a new Pakistan, and has certainly reinvented himself. In the west, he is still seen as a cosmopolitan playboy; in Pakistan he has wooed the religious right, vowing to defend the blasphemy law and describing the Taliban’s fight in Afghanistan as a “holy war”. He has portrayed himself as the outsider who will clean up a dirty business, despite his elite background and reliance on “electables” who bring their own vote banks as they switch between parties.

There was some relief at his conciliatory tone as he claimed victory. But his campaigning record is not encouraging, and now he must actually run a country – in so far as he is allowed to. His party has governed one province. He takes over a country struggling with violence, extremism, poverty and a worsening economic situation, in a fraught international environment; a mightier China, tense relations with the US, India and Afghanistan. Whatever he does will be done within the context of a strengthened military. He claimed the country’s “umpires” would step back if he were elected. But Mr Khan’s promised “New Pakistan” seems likely to look rather like the old variety.