When Pakistan’s government censored the media, former Prime Minister Imran Khan’s party posted campaign videos on TikTok. When the police barred his supporters from holding rallies, they hosted virtual gatherings online.
And when Mr. Khan ended up behind bars, his supporters produced speeches using artificial intelligence to simulate his voice.
Mr. Khan’s message resonated with millions across the country who were frustrated by the country’s economic crisis and old political dynasties: Pakistan has been on a steep decline for decades, he explained, and only he could restore its former greatness.
The success of candidates aligned with Mr. Khan’s party in last week’s election — snagging more seats than any other in Parliament — was a stunning upset in Pakistani politics. Since Mr. Khan fell out with the country’s generals and was ousted by Parliament in 2022, his supporters had faced a military-led crackdown that experts said was designed to sideline the former prime minister.
His success marked the first time in Pakistan’s recent history that the political strategy used by the country’s powerful military for decades to keep its grip on power had suddenly veered off course. It also proved how Mr. Khan’s populist rhetoric and the country’s internet-savvy youth bulge are rewriting politics in Pakistan, a nuclear-armed nation of 240 million people that has struggled with military coups since its founding 76 years ago.
Now, as the parties of both Mr. Khan and Nawaz Sharif, the three-time former prime minister, race to win over other lawmakers and establish a coalition government, Pakistan is in uncharted territory. If Mr. Khan’s party succeeds — an outcome many analysts believe is unlikely — it would be the first time in Pakistan’s history that a civilian government would be led by a party at odds with the military and whose leader is behind bars.
No matter the outcome, Mr. Khan’s party “proved it is an unshakable political presence, tapping into the dissatisfaction of Pakistan’s youth,” said Adam Weinstein, deputy director of the Middle East program at the Quincy Institute, a Washington-based think tank. “The old playbook for shaping the country’s politics is outdated; social media and youth mobilization have become game changers.”
For roughly half of Pakistan’s history, the military has ruled the country directly. When civilian governments have been allowed to come to power, they were led by a handful of leaders — including Mr. Khan’s rival in this election, Mr. Sharif — who were typically ushered into power with the support of the generals.
Those military-aligned leaders built political parties around their family dynasties, passing party leadership from one generation to another — and keeping political power within a tightknit circle. But in recent years, as the country’s young population has ballooned to around half its electorate, there has been a growing frustration with that system, analysts say.
Young people felt shut out of the Pakistan’s political system because “someone in the family will always get the top slot,” said Zaigham Khan, a political analyst based in Islamabad. “The old parties are becoming obsolete because they refuse to change — and that created a vacuum for someone like Imran Khan.”
While Mr. Khan initially rose to political prominence with the military’s help, after his ouster he capitalized on young people’s yearning for change to strengthen his political base independent of the generals. His party, Pakistan Tehreek-e-Insaf, or P.T.I., produced political campaigns on social media — outside the reach of state censorship — that young people say stirred a political awakening for their generation.
In viral videos, Mr. Khan railed against the country’s generals, whom he blamed for his ouster in 2022. He described how the military operated like a “deep state” governing politics from behind-the-scenes, and claimed that the United States had colluded with Pakistani officials on his removal from power. He described himself as a reformer who would bring change.
His message galvanized young people across the country.
“I’m voting for change. I’m fed up with this whole system of political parties that have been running the country,” said Usman Saeed, 36, as he stood outside a polling station in Lahore on Thursday after casting his vote for P.T.I. candidates. “They’ve put Imran Khan in jail — that’s the main issue — it shows it’s all been managed by the establishment,” he added, referring to the military.
Few of these voters remembered the discontent of Mr. Khan’s last months in office, when his popularity plummeted as inflation soared. Had he been allowed to complete his term, many analysts said, his party likely would not have won the next general elections.
But even after his ouster, the country’s military leaders appeared to underestimate the country’s shifting political sands. As Mr. Khan made a political comeback, the generals turned to their old playbook to sideline him.
Authorities slapped Mr. Khan with dozens of charges that resulted in four separate sentences totaling 34 years in prison. They arrested hundreds of his supporters and — for the first time — cast a much wider net, going after Pakistanis in the country’s elite, even those with close ties to the military itself.
That intimidation campaign appeared to only bolster support for Mr. Khan. Because the crackdown was publicized widely on social media, it exposed and turned more of the public against the military’s heavy hand in politics. Many people who cast ballots last week for Mr. Khan’s party said they did so simply to spite the generals.
Looming over the political scramble now to form a new government are widespread allegations of the military tampering with vote counts and the promises by Mr. Khan’s party of long, bruising court battles to challenge dozens of results it says the military rigged. On Sunday, thousands of Mr. Khan’s supporters took to the streets across the country to express anger over allegations of election fraud — protests that were met with police batons and tear gas.
“P.T.I. is a peaceful party that has ushered in a revolution through the ballot,” the party’s head in Punjab Province, Hammad Azhar, said on the platform known as X. “We will not allow our struggle to be hijacked by nefarious designs.”
The political showdown has put the country — whose history is littered with military coups and mass unrest — on edge. Most agree that despite the election’s results showing just how many Pakistanis are rejecting the country’s broken political system, Pakistan is still not moving in a direction of greater stability or a stronger democracy.
“Even if the balance of power is tilting in favor of the political parties, will they actually act democratic themselves?” said Bilal Gilani, the executive director of Gallup Pakistan. “Or will they become more fascist in their ideologies? Will they exclude the people who haven’t voted for them? That’s the question now.”
Zia ur-Rehman contributed reporting.