ISLAMABAD — Less than a week ago, Imran Khan was a maverick candidate for parliament, shouting himself hoarse above loudspeaker music at youth rallies. Today, he is a prime minister in waiting, graciously receiving Middle Eastern ambassadors in his hillside mansion above the capital. Outside, supporters have thronged the barricaded entrance, dancing and drumming in a seemingly inexhaustible frenzy of celebration.

In the four days since Khan, a former cricket star turned anti-corruption crusader, trounced the long-ruling Pakistan Muslim League and every other party in the polls, a nationwide burst of euphoria has remained at fever pitch. But already, the moment of triumph is being tempered by somber reflection on the scope of the challenges Khan faces as he attempts to transform a vast, poor country beset by a range of entrenched ills.

“He is our last hope. All the other parties are full of thieves,” said Luqman Khan, 21, a fabric shop worker here who volunteered for Khan and voted for the first time on Wednesday. During the campaign, he said in a slightly sharper tone, “we all went out and told everyone he was a new, clean person who would change things. Now we expect he will fulfill those promises.”

Khan, who campaigned on a single agenda of ending official corruption and bringing justice to the public, won a comfortable plurality of seats, though not enough to rule without forming a coalition. His party swept the polls across the country, unseating dozens of powerful legislators who have since been scrambling to diminish and cast doubt on his victory. They have complained of vote-rigging and military meddling, demanded ballot recounts and threatened to thwart him on every legislative change.

But the numerical and psychological reality of Khan’s historic victory has begun to sink in. Analysts are comparing it to the birth of the Pakistan People’s Party in 1967, when Zulfiqar Ali Bhutto, a wealthy socialist ideologue, was elected to power and began to revolutionize the country. Khan, a more conservative politician, envisions a more modest transformation, but one that would challenge the privileged elite at its core.

Amid the clamor of protest, Khan and his team have spent the past few days quietly greeting well-wishers and courting enough support from independents and others to govern both the nation and Punjab province, the country’s most populous and consequential region. His aides said they expect him to be sworn in as prime minister before Aug. 14.

“Khan won. Period,” commentator Fahd Husain began in the online Express Tribune on Sunday. “This election was about hopes, expectations and aspirations. It was also about growing up as a democracy; about maturing as a nation privileged with fundamental rights and liberties; about flowering as a society that is shrugging off the bitter past of a menacing State and walking into a better future of a caring State. The verdict of this election is clear: Khan won. Period.”

But like others, Husain posed questions about whether Khan has raised public expectations too high, whether the controversy being whipped up by his opponents over the polls will shadow his efforts and render his agenda unenforceable, and how he will resolve his own contradictions as a leader who demands fairness for the poor but also has shown a soft spot for the powerful army and religious extremists.

“The real burden is on the victor,” Husain wrote. “His is now the mandate to birth a new Pakistan from the womb of the old one. New Pakistan however is nothing if it is not better Pakistan. Khan’s words and actions have so [far] painted a dual Pakistan — often a contradictory Pakistan. Can his words reconcile with his beliefs?”

In several dozen interviews since the election, supporters of Khan and his Pakistan Justice Movement expressed a similar mixture of desperate hope and creeping skepticism that Khan — or anyone — could somehow purge Pakistan of the corruption that pervades every arena of public life, where small bribes speed applications for driver’s licenses, big ones allow murder suspects to walk out of jail and political influence and favors count far more than the law.

Many people, however, pointed optimistically to the recent experience of Khyber Pakhtunkhwa province, where Khan’s party governed for the past five years and swept the legislative contests Wednesday. Under an administration run by officials from his party, they said, the education and health systems were improved, and most significant, the behavior of police was transformed from routine bribe-seeking to by-the-book law enforcement.

Activists of the Jamiat Ulema-e Islam political party protest alleged election rigging in Peshawar. Cricket hero Imran Khan has swept to an emphatic victory in a Pakistani election that was criticized by foreign observers. (Abdul Majeed/AFP/Getty Images)

If Khan can successfully replicate that accomplishment on a national level, analysts said, it would come closer than any Pakistani government has in over half a century to fulfilling the vision of its founder, Mohammad Ali Jinnah — a democrat who sought to build a nation where everyone was treated equally regardless of religion or other factors.

One businessman from Islamabad described being pulled over for running a red light while recently visiting Khyber Pakhtunkhwa. He said he told the traffic officer he had come a long way and offered to pay him a small “fine” on the spot. To his astonishment, he said, the cop gave him a polite smile and responded, “Sir, this is a new Pakistan. Here is your ticket.”

Some critics pointed out that while Khan has nurtured a reformist, anti-establishment image, his political team includes some controversial business owners and politicians cut from the traditional Pakistani mold. But others credited him as the main legal protagonist in a court case against former prime minister Nawaz Sharif, who was accused of hiding family wealth overseas, was barred from political office by the Supreme Court and recently began serving a 10-year prison sentence.

“Now our three-time prime minister is in jail, and the credit goes to our leader,” said Numan Sheraz, 44, a trader in Peshawar, the capital of Khyber Pakhtunkhwa.

“Mr. Khan gave us voice and awareness about the system and how to fight corruption,” he said. “Now more corrupt politicians and officers will face the demand for accountability.”

Whatever Khan achieves, analysts said, he has already broken a cycle in which two political dynasties have repeatedly switched back and forth in power rather than opening up the political system to others. Not only did he appeal to young and first-time voters, results showed, but to older ones who had grown disgusted with the traditional rulers and joined Khan’s party out of frustration.

“My family always voted for the People’s Party, and I was the only one supporting Imran. Now they have all switched, too,” said Mohammad Sulieman, 25, a taxi driver. “All Pakistanis want the same thing — more jobs, more water, less poverty, less corruption. We want what is good for Pakistan, so we have to support the person who will solve its problems.”