LAHORE, Pakistan — Imran Khan, the charismatic cricket star-turned-opposition-leader, is brimming with newfound confidence.
With general elections expected in July, Mr. Khan made a spirited claim to lead the next government when he addressed thousands of his supporters who had gathered in the politically important city of Lahore a week ago. The rally kicked off the election season, and other political parties have begun campaigning around the country.
Mr. Khan — a populist with whose nationalist appeal rests in part on an anti-American platform — is the main challenger to the political party of former Prime Minister Nawaz Sharif, who was ousted last year by the Supreme Court after a corruption inquiry. Mr. Sharif was barred from holding public office, and he faces a verdict next month on corruption charges.
With Mr. Sharif looking at possible jail time, and several leaders of his party, the Pakistan Muslim League-Nawaz, ensnared in corruption investigations, Mr. Khan says his time has arrived. He presents himself as an alternative to what he calls a corrupt political elite and says he will work to improve education, health and the environment.
His prospects have brightened in light of his warming ties with the military, which controls the main levers of power in Pakistan and has dominated foreign and security policies for decades. Mr. Sharif’s efforts to assert civilian control over the military during his last term failed, turning him into an intensely hated figure among the military establishment.
Mr. Khan, on the other hand, has no qualms about working with the military.
“I think a democratic government rules from moral authority,” Mr. Khan said in an interview at a party office in Lahore. “And if you don’t have moral authority, then those who have the physical authority assert themselves. In my opinion, it is the Pakistan Army and not an enemy army. I will carry the army with me.”
In recent months, the army chief, Gen. Qamar Javed Bajwa, has increased his clout, while dissenting voices in the country have come under greater pressure and restrictions on the media have increased.
Mr. Sharif has accused the army and judiciary of working together to have him removed from office, depriving his party of a level playing field in the general elections. Both the military and the judiciary deny the allegations, which Mr. Sharif repeated last week at a rally in Punjab Province.
In the coming election, the Pakistan Muslim League-Nawaz party “will be up against forces that cannot be seen,” Mr. Sharif said, in a veiled reference to the military’s intelligence agencies.
Hasan Askari Rizvi, an analyst based in Lahore, said Mr. Khan’s political stock has risen as his relationship with the military has gotten closer.
“Imran has realized that if you want to run Pakistan, you have to work with the military because of the internal and external challenges,” Mr. Rizvi said. “By fighting with the military, you cannot run the state.”
Those relations have improved despite Mr. Khan’s long opposition to the military’s operations against Taliban insurgents in the tribal regions bordering Afghanistan and its cooperation with the United States.
“I hear all this stuff about how the army is influential in Pakistan. The army depends on one man. Whoever is the army chief, the army policy goes the way of the army chief,” Mr. Khan said in the interview.
Mr. Khan then praised General Bajwa.
“It’s the first time that I am seeing an army chief saying time and again that ‘I will ensure free and fair elections,’ which is the one thing that we want. That’s all I want. This is music to our ears.”
Mr. Khan blames what he calls the corrupt and inept civilian leadership of the past for the imbalance in civilian and military relations. He is also critical of neighboring India and Afghanistan, saying their hostility toward Pakistan forces the military to play an outsize role in the country.
With adversarial neighbors, “clearly, the military will have a bigger say in the security policy,” he said. “But I don’t blame the army. I blame the most corrupt governments whose main concern has only been making corrupt money and protecting the corrupt money. They could easily have taken a more assertive role in foreign policy.”
He added: “I have very clear foreign policy objectives, and where there are security concerns of the army, we will address them. We will sit down. It is our army.”
Mr. Khan has been a bitter critic of the United States, and in recent years, the Pakistan military has also veered away from its traditionally close ties with the United States, looking toward China and Russia.
Critics say Mr. Khan is pandering to the military.
Maryam Nawaz, the daughter and political heir apparent of the ousted prime minister, goes as far as calling Mr. Khan a “stooge” and “pawn” of the military and its intelligence agencies. Mr. Khan dismisses such criticism.
In the last elections, in 2013, Mr. Khan’s party won 33 of the 342 seats in the National Assembly. But he remained the key opposition figure, keeping Mr. Sharif off balance through a mix of street agitation and court petitions, which finally led to Mr. Sharif’s dismissal last July.
“I think we should take Imran Khan much more seriously this time,” said Zaigham Khan, a political analyst and newspaper columnist. “He is not alone.”