The votes cast in Pakistan’s election are still being counted (or rigged, as some allege). But it is already clear that Imran Khan, leader of the Pakistan Tehreek-e-Insaf (PTI) will be the next prime minister. The previous governing party, Nawaz Sharif’s PML-N is trailing badly and the PPP, led by Benazir Bhutto’s son and widower, is even further behind. The total number of general seats up for grabs in parliament is 272, meaning that to command a majority, the magic number is 137.

It looks unlikely that the PTI will reach that number by itself. However, a quirk of the electoral process in Pakistan is that after the final tally of seats, independent candidates can choose to change their party affiliation and join another (normally the winning) party. In 2013, the PML-N did not win an outright majority but was able to form a government when 19 independents joined its ranks. The seats are then topped up with the party lists for the 10 religious minority seats and the 60 women’s seats, on the basis of the party percentage of seats, from those receiving over 5% of the vote. Imran Khan will almost certainly secure a majority through this method, or through an alliance with smaller parties.

The electoral process has been dogged by allegations of pre-poll fixing. One spokesman for the PML-N described them as the “dirtiest in Pakistan’s history”. Of particular concern has been the suggestion that members of the PML-N, including leader Nawaz Sharif, were subject to politically motivated legal sanctions. A media crackdown and the engineered defections of “electables” from the PML-N also caused a stir.

The removal of Sharif from the campaign trail through his imprisonment deprived the PML-N of its star campaigner. Khan’s victory has therefore seemed the most likely outcome for some time. However, election night was controversial. Major delays in the results were blamed on a computing failure but Twitter was alive with allegations of polling agents being removed from polling stations and being unable to sign Form 45, which would certify the results for those stations.

Politicians and activists were quick to make the link between this development and the deployment of 371,000 soldiers to ensure the elections would be “free, fair and transparent”.

All the main parties have rejected the fairness of the result. Despite claims that rejecting an election result is a common occurrence in Pakistan, the PPP did not dispute the PMLN victory in 2013 and the PMLN did not dispute the victory of the PPP in 2008. Both do so today. It’s striking that parties from across the political spectrum, including the Islamic parties, are speaking out on this occasion. It’s less clear what their next move will be, including whether they will boycott parliament.

Little is likely to change for Pakistan’s foreign relations under Khan. Although he has a history of opposing US drone attacks and previously urged dialogue with, rather than action against, the Pakistan Taliban, it is the military rather than civilian leaders that control foreign policy in Pakistan. Whether cooperation with the Americans or Afghanistan continues is the military’s call, not Khan’s. Pakistan’s relations with the US have improved in recent months, following its cooperation over the killing of the Pakistan Taliban leader Maluana Fazlullah in June this year, but it remains under international criticism for having “failed to act against terror financing on its soil”.

Future relations with India are more uncertain. Khan taunted Nawaz Sharif over his “friendship” with Narendra Modi before the election. Khan has since said he would seek good relations with India but it’s the Pakistani military which calls the shots on relations with India, not elected prime ministers.

Although there are legitimate questions over the fairness of these elections, a prolonged period of domestic instability will be damaging for Pakistan. It faces a number of challenges in the coming months. Its foreign exchange reserves can cover only two months’ worth of imports and most observers expect it to have to go to the IMF for support. This in turn could affect relations with China, at a time when the two countries’ major shared infrastructure projects are coming under increased international scrutiny. If Khan does become Pakistan’s next prime minister, his term will be far from easy.

This article was originally published on The Conversation