Pakistan’s Prime Minister Shahid Khaqan Abbasi says the country’s forthcoming general election will be conducted by “aliens”, rather than by the election commission. His predecessor Nawaz Sharif, ousted last July by a Supreme Court ruling, is also convinced the ruling Pakistan Muslim League-Nawaz (PML-N) party will contest the polls not against the two major opposition parties, but against extraterrestrials.

Sharif and Abbasi are referring to is a series of political events that since 2014 have undermined the authority of the government. Commentators say they have rendered Pakistan’s democracy an elaborate facade – one where a supposedly civilian government is in place, but the reins of power are held by the military.

But apparently democracy is flourishing in Pakistan like never before. At the end of this month, a second consecutive elected government will complete its five-year term and is on track to hand over power to a third after a general election in July. This is unprecedented in the country’s 71-year history.

Pakistan’s military, having directly ruled the country for 31 of the 61 years before the restoration of democracy in 2008, is now publicly committed to upholding the democratic constitution. And the judiciary, having previously found legal grounds to justify military takeovers, now regularly warns it will not permit further disruptions to the constitutional democratic process.

If you doubt who is in charge in Pakistan …

But the kind of ET that Sharif and Abbasi have been talking about struck last Sunday with an assassination attempt on interior minister Ahsan Iqbal, who is the point man for the China-Pakistan Economic Corridor (CPEC) project linking Gwadar Port on the Arabian Sea with Xinjiang. The shooter had links to the Tehreek-e-Labbaik Ya Rasool-Allah (TLY), an Islamist party that has held the federal and Punjab provincial governments to ransom since last year. The TLY blocked a major access point to Islamabad for 22 days in November to force the withdrawal of an amendment to the language of an oath that Muslim members of parliament must swear. A minister was forced to step down. It blockaded Lahore for 10 days in April, backing off only when a Punjab government leader secretly “begged forgiveness” from its leader, according to commentator Nusrat Javeed.

The assassination attempt on a minister underlines fears of religious extremists derailing the coming election. With democratic politicians rendered impotent by elements like TLY, Pakistan’s military is now ideally placed to influence the electoral campaign to ensure no single party achieves a majority. This would ensure the incoming government does not have a popular mandate strong enough to challenge it.

“On the ground, the creeping coup against the elected government for the last four years has entered its final stage,” said Afrasiab Khattak, a former senator and veteran human rights activist, in a recent commentary.

The “creeping coup” started a little more than year after the May 2013 general election, when the government of Sharif, appointed prime minister for a third time, came under pressure from former cricket star Imran Khan, chairman of the opposition Pakistan Movement for Justice party.

Contesting the results of 35 constituencies in populous Punjab province, Khan took to the streets and forcibly occupied the government district in Islamabad from August to December 2014. Military units deployed at the government’s behest to protect state institutions did not intervene. Khan repeatedly said the government would fall when “the umpire raises his finger”, referring to the army chief of staff, General Raheel Sharif.

How India-Pakistan tensions (and US-China rivalry) are raising nuclear stakes

The military did not endorse Khan’s demand for fresh elections. Nawaz Sharif’s administration survived. Control of foreign and security policymaking was, however, ceded to the military as a quid pro quo – but not before a cabinet minister was sacked for telling the BBC the entire affair had been orchestrated by the military’s intelligence chief.

The elected government’s subsequent attempts to reassert a degree of control over foreign policy failed. In October 2016, Dawn, the country’s leading English-language newspaper, reported the prime minister had confronted the military over its reluctance to crack down on Islamists involved in terrorist attacks on neighbouring Afghanistan and India. Pakistan faced growing diplomatic isolation and even China warned it could not indefinitely exercise its veto at the UN Security Council to block moves to declare Pakistan a state sponsor of terrorism, Dawn reported. The military blamed the government for leaking a fake news story and rejected an inquiry that exonerated ministers and officials of the prime minister’s office. The affair blew over, but only after the sacrifice of another cabinet member.

The “Dawn leaks” scandal put intense pressure on media companies critical of the military’s resurgent role in politics. The distribution of newspapers and cable channels by Dawn and Geo-Jang, the country’s largest media business, has been hit by unofficial bans. Restrictions have also been placed on media critical of the judiciary. Television channels routinely mute live speeches by politicians and newspapers withhold regular columns. Television journalist Kamran Khan compares the climate with that under military dictator Zia ul Haq, who ruled from 1977 to 1988. “It’s even worse because we’re under so-called democracy,” said Khan.

What do you get if you cross Pakistan’s Game of Thrones and China’s Belt and Road?

The military tightened the screws on Nawaz Sharif after the Panama Papers leaked from law firm Mossack Fonseca in April 2016 showed his family had accumulated substantial overseas assets. A pliant Supreme Court disqualified him from holding public office for life. Dispensing with the rules of evidence, the Supreme Court based its verdict on a convoluted interpretation of vague personal character-related articles of the constitution inserted by Zia ul Haq in 1985, which insulated him from civilian leaders’ challenge. The precedent set by the verdict has been used several times to neutralise other political bigwigs in recent months, leading to accusations of “judicial martial law”.

As mainstream parties wither under the military’s heat, outfits like the TLY have stepped into the vacuum. In the restive Balochistan province, through which CPEC passes, political parties have accused the military of toppling the government led by Nawaz Sharif’s PML-N. His party has begun to fragment from within, with rebel party members in several provinces breaking away.

Other ruling party parliamentarians “have received phone calls and are being asked to change their loyalties”, Prime Minister Abbasi told Dawn.

This power tussle within Pakistan’s biggest national party, the growth of bit players with disproportionate influence on the electoral process, and the weakening of democratic institutions all paint a grim picture even as the country maintains the appearances of a democracy.

The election and scheduled transfer of power to a third consecutive democratic administration is “what is expected if we go by the constitutional fiction,” said former senator Khattak.

But if the anticipated result is not to the military’s liking, many worry the election may be postponed by the judiciary long enough to see Nawaz Sharif jailed on criminal charges, removing the biggest source of civilian challenge to the military.

“I fear that if it is surmised that the election would not yield the desired results, it may be delayed, perhaps indefinitely,” Javeed said.