In 2011 and 2012, when Imran Khan, the former international cricket star and London night-club Lothario, first emerged from Pakistan’s political wilderness, he rode an Arab Spring-inspired wave of urban middle-class hopes for cleaner politics and better government. If Khan, a celebrity with his own income, came to power, the thinking went, then he might sweep away the family-based nepotism and corruption that had so curtailed Pakistan’s progress since independence, in 1947, and perhaps also loosen the Army’s grip on the country. Hundreds of thousands of enthusiastic, educated young people attended his rallies in cities such as Lahore, the country’s cultural capital. Khan fired them up by talking about a coming revolution in Pakistani politics, one that would modernize governance, attack inequality, and level the economic playing field through the impartial rule of law.

Khan’s tiny political party, Tehreek-e-Insaf, or P.T.I., expanded rapidly, and it surged in national and provincial elections, ultimately leading a provincial government for a number of years, to mixed reviews. But Khan fell short of winning a high national office and, in recent years, he has largely played a role of opposition agitator and provocateur. Now he appears to be within close reach of his ambition to serve as the Prime Minister. According to results in Pakistan’s general election, held on Wednesday, the P.T.I. won the most seats, by far, in Parliament, although not an absolute majority. The expectation is that Khan will be able to negotiate a majority coalition by attracting support from smaller parties and independent members of parliament.

On Thursday night, Khan delivered a nationally televised address, and he reiterated his promises to fight corruption and lift up the country’s poor. Since he retired from cricket, in 1992, after leading Pakistan to a stunning World Cup victory in Australia, Khan, who is now sixty-five, has undergone a complicated reëngagement with religion. In his speech, he cited the Prophet Muhammad’s seventh-century founding of Medina, in modern Saudi Arabia, as a model for his vision of a new domestic welfare state, “where we take responsibility for our weaker classes,” as he put it. “Our state institutions will be so strong that they will stop corruption. Accountability will start with me, then my ministers, and then it will go from there,” he added. “We will set an example of how the law is the same for everyone. If the West is ahead of us today, it is because their laws are not discriminatory,” he said. “This will be our biggest guiding principle.”

A challenge facing Khan is that, for many Pakistanis, the optimism that accompanied his initial rise has yielded to wariness, if not outright cynicism. His critics see him as an opportunist who is poised for power now because he has accepted back-door support from the country’s powerful Army. During the past few years, the Army and its allies have used corruption charges to marginalize the Pakistan Muslim League party, led by the three-time Prime Minister Nawaz Sharif, who was recently jailed after returning from his latest exile. Khan denies collusion with the Army, and declares that he will be his own man, but there can be little doubt that the military, despite its denials, engineered the latest fall from power by Sharif, and that Khan benefitted from it.

There can also be little doubt that the office of Prime Minister of Pakistan will remain the country’s second most powerful position, after the Chief of Army Staff, currently held by General Qamar Javed Bajwa. Bajwa and his senior generals exercise authority well beyond their constitutional role, influencing the media, politics, and the judiciary. Their power has only consolidated in recent years, as evidenced in military-sanctioned crackdowns on media outlets critical of the “establishment” (as the military is euphemistically known in Pakistan), human-rights activists, and other sections of civil society. However, for more than a decade, the Army has found it preferable to rule Pakistan indirectly, focussing on national security and foreign policy, and leaving the messy and intractable problems of poverty, energy deficits, and development to the Prime Minister and the Cabinet. Imran Khan is only the latest in a series of junior partners whom the Army will expect to concentrate on the economy and other domestic matters but tread lightly on foreign affairs.

Khan’s speech on Thursday touched mainly on domestic policy, but he did comment on Afghanistan, where the United States remains mired in a seventeen-year, stalemated war, and on relations with Washington. He called Afghanistan “a country that has suffered the most in the war on terror.” At a time when the Trump Administration has renewed efforts to find a negotiated solution to the war that might allow the United States to reduce, or even eliminate, its military presence in the country, Khan has expressed support for such a strategy. “Afghanistan’s people need peace. We want peace there. If there is peace in Afghanistan, there will be peace in Pakistan.”

Khan’s attitude toward the Taliban has shifted over the years, but his current outlook seems aligned with the Army’s. That is, where Taliban factions leave Pakistan alone and seek to be accommodated in Afghan politics, he is sympathetic to, or at least tolerant of, the movement’s legitimacy. (Since the Afghan Taliban emerged, in 1994, the Pakistan Army and its principal intelligence service, Inter-Services Intelligence, or I.S.I., has sought to use the movement as a source of influence in Afghanistan, and as a check on India’s ambitions in the country.) Khan also describes Pakistan as a victim of the American-led war in Afghanistan. He has denounced U.S. drone strikes inside Pakistan and rejected the premises of U.S. counterterrorism policy in the region. “I never thought the Taliban were a threat to Pakistan,” he told me in 2012, when I interviewed him for a Profile in The New Yorker. Still, it has always been hard to think of Khan as anti-Western, in the sense that he was educated in Pakistan’s finest British-inspired prep school, attended Oxford University, married a British woman (the first of three wives), and thrived as one of the first English-speaking global athletic superstars of the satellite-TV age. His Westernness has always been a part of his identity, and even of his political appeal inside Pakistan.

Moreover, in his speech, Khan did not reject accommodation with the Trump Administration, which has suspended aid to the country, attempted to pressure the Army to arrest members of the Taliban and other militant leaders hiding in its territory, and tried to support a serious peace process to stabilize Afghanistan. With the United States, “We want to have a mutually beneficial relationship,” Khan said. “Up until now, that has been one-way. The U.S. thinks it gives us aid to fight their war.” He added, “We want a balanced relationship.”

If Khan does become the Prime Minister, he will inherit an economy in crisis, with debts rising and foreign reserves shrinking, likely presaging yet another painful round of bailout negotiations with the International Monetary Fund. The economy is growing, with the gross domestic product forecast to rise nearly six per cent this year, but corruption, persistent terrorist violence, and decades of bad government have saddled the country with an almost bottomless list of structural problems, such as illiteracy, sectarianism, and public-health crises. It’s no wonder that the Army does not wish to run Pakistan directly these days. Better to let ambitious civilian politicians like Khan take on the intractable problems, while the generals take care of themselves offstage. If Khan actually changes Pakistan in the ways that he has promised, it will be a greater miracle than any of those he achieved on the cricket pitch.