In 1992, when Pakistan won its only Cricket World Cup, Prime Minister Nawaz Sharif was asked by a television host if the team captain, Imran Khan, a national heartthrob, would be right for his party if Mr. Khan went into politics.
“I offered him a long time ago, but he declined. I don’t know why,” Mr. Sharif said, patting Mr. Khan’s shoulder as everyone who had gathered around burst into laughter.
Mr. Khan, a charismatic athlete well known then for his playboy image and affairs with British socialites, did go into politics a few years later through his own party, Pakistan Tehreek-e-Insaf, or P.T.I.
On Friday, the country’s Supreme Court ruled that corruption accusations against Mr. Sharif, 67, a veteran politician who thrice served as prime minister and has defined Pakistan’s politics for decades, were sufficient to remove him from office.
For Mr. Khan, 64, the moment was sweet. He had been the main petitioner before the court and fomented widespread street protests against Mr. Sharif, emerging as the strongest challenger to the former prime minister and his political legacy.
But Mr. Khan’s path to victory in the next general election, set for mid-2018, is far from assured, according to analysts, including Moeed Yusuf, associate vice president of the Asia Center at the United States Institute of Peace, whose research and work centers on Pakistan.
“In some ways, this is a clear victory; there is no question about that,” Mr. Yusuf, who is visiting Pakistan, said in an interview. “Sans Panama Papers scandal, PML-N, the ruling party, was sitting pretty for the next elections.”
The scandal he referred to comprised disclosures in last year’s leaked Panama Papers that Mr. Sharif and his children hid much of their enormous wealth in offshore bank accounts and related investments.
Still, Mr. Yusuf said, he did not believe Mr. Khan was “closer to a victory in the elections” than he had been before the ouster. “Whether he gets closer or not depends on his own behavior and whether Nawaz overplays his hand and what accountability court does.”
The Supreme Court has directed the accountability court to decide corruption cases against Mr. Sharif and his family within in six months. But there is skepticism that the courts will reach a decisive verdict against the Sharif family and speculation that even if Mr. Sharif cannot run again, his Pakistan Muslim League-Nawaz Party will continue to dominate Parliament.
On Sunday evening, Mr. Khan was to address a large political rally in Islamabad, hoping to kick-start a new round of rollicking opposition to the governing party.
When Mr. Khan started the P.T.I. party in 1996, he was considered a political nobody and squirmed on the sidelines for decades. His party had just one seat in Parliament after the 2002 elections and boycotted the 2008 elections.
Not until 2011 did Mr. Khan find himself center stage as he captured the public’s imagination and began drawing hundreds of thousands of Pakistanis to his political rallies. Most people in the audiences were educated, urban youths, disgruntled with the system and energized by Mr. Khan’s populist, anticorruption and anti-American message. The party also picked up vast support among the Pakistani expatriate community, and Mr. Khan’s supporters are dominant on social media.
Despite his huge urban base, Mr. Khan has found it hard to prevail over Mr. Sharif’s Pakistan Muslim League-Nawaz Party, especially in Punjab, the former prime minister’s power base, and two other provinces.
Mr. Sharif remains deeply entrenched through a vast network of political patronage. His party won the 2013 general elections with an overwhelming majority. Mr. Khan’s party currently holds just 33 of the 342 seats in the National Assembly.
But since the last elections, Mr. Khan has been at the forefront of political opposition to Mr. Sharif, portraying him as the face of the status quo and corrupt practices that have gnawed at the political system.
In many ways, Mr. Khan did not let Mr. Sharif settle into office. His popular agitation kept the prime minister perpetually unsettled and fighting to gain traction despite his party’s success at the polls. The situation was made more difficult by Mr. Sharif’s constant friction with the powerful military, elements of which favor Mr. Khan.
Soon after the elections, Mr. Khan accused Mr. Sharif of vote rigging. In 2014 he led thousands of protesters in a siege of Islamabad, the capital, for months.
Shortly after the Panama Papers revelations, Mr. Khan again tried to lay siege to Islamabad in November 2016. He forced the Supreme Court to take up the corruption case against Mr. Sharif, which culminated in the prime minister’s ouster on Friday.
Some analysts say Mr. Sharif’s party can survive if the transition to his successor is smooth and energy and infrastructure projects are completed well before the next elections.
“If Nawaz manages a smooth transition to the next prime minister,” Mr. Yusuf said, his party “still has a clear edge going into the next elections.”
Other analysts say the country’s powerful generals might be reluctant to see Mr. Khan in power. Critics dismiss him as soft on militancy; some even ridicule him with the nickname “Taliban Khan.”
Mr. Khan has no experience with governing and has shown an aptitude more for street agitation than working with Parliament to bring about change. Many diplomats expressed shock at what they see as his disregard for the parliamentary process.
But enamored supporters say Mr. Khan is not corrupt like traditional politicians and point to his philanthropic work as proof that he will do more good for the country.
Husain Haqqani, the director of Hudson Institute and a former Pakistani ambassador in Washington, described Mr. Khan as an “instrument” to force Mr. Sharif from power but not to succeed him.
“He is not the kind of man the establishment would like to be in charge,” said Mr. Haqqani, a longtime observer of Pakistani politics. “He is mercurial and unpredictable. It took the generals two decades to cut Nawaz Sharif to size after they created a political career for him. They will not make the same mistake again, of helping someone they cannot control.”
Mr. Haqqani said he expected the current Parliament to complete its term, which also ends in mid-2018.
“PML-N has a clear majority in the Parliament and Punjab,” he said. The party’s 188 seats give it a decided majority in the lower house, the National Assembly. Early next year it is also expected to have a majority in the Senate, the upper chamber, where it currently has only one seat fewer than the Pakistan Peoples Party.
“There is no legal basis for an early election,” Mr. Haqqani said. “PML-N will be allowed to limp to the end of its tenure.”
Mr. Khan too faces cases against him in the Supreme Court and the election commission, stemming from accusations of hiding assets and of foreign funding of his political party. There has been speculation that the courts could bar him from Parliament over these accusations, speculation that Mr. Khan laughs off.
“How can I be disqualified?” he said in an interview. “I was never a public officeholder. The whole world knew I was playing cricket. I have given my whole money trail to the Supreme Court. It is just blackmail.”
Mr. Yusuf, of the United States Institute of Peace, said he worried that “this could be Imran’s Trump moment.”
“What I mean is that you are a leader of a party or campaign and you have basically defied all odds to secure a major political victory,” he said, “and now you could be in a situation where you feel you do not have to take counsel from the people who are going to advise patience, advise taking the long course, rather than declaring victory and overplaying your hand.”