KABUL — A mix of sharp criticism from opposition politicians and public anger over economic woes is suddenly challenging the dominance of Pakistan's long-powerful military, even as the United States and other foreign governments seek help from Pakistan's generals in salvaging Afghan peace talks amid growing Taliban violence.

In the past month, an alliance of 11 political parties called the Pakistan Democratic Movement has formed and held two large rallies, calling on Prime Minister Imran Khan to resign and demanding that the military stay out of politics. The movement includes the country’s two major parties, which have been fierce rivals for decades.

Khan came to power in 2018 on an agenda of liberal reforms but is widely seen as backed by the armed forces. Long the country’s dominant institution, the military has often privately influenced civilian rule and periodically ousted elected leaders, most recently in the 1999 bloodless coup that removed Prime Minister Nawaz Sharif.

Until now, though, the military has remained widely admired despite periodic crackdowns on dissent and journalistic freedom. It is rarely criticized except in oblique terms and is not expected to be seriously damaged by the current protests, which have largely been galvanized by frustration over rampant inflation that has doubled the prices of food staples in the poor nation of 230 million.

But last week, Sharif shocked the country by denouncing the army chief, Gen. Qamar Javed Bajwa, at the first rally of the Pakistan Democratic Movement. In a stunning departure from Pakistani norms, the three-time premier accused Bajwa of backing his removal from office on corruption charges in 2017 and rigging the 2018 elections. It was the first time an establishment politician had ever made such accusations.

“General Qamar Javed Bajwa, you packed up our government and put the nation at the altar of your wishes,” Sharif said in Urdu. “You rejected the people’s choice in the elections and installed an inefficient and incapable group of people,” leading to an economic catastrophe. “General Bajwa, you will have to answer for inflated electricity bills, shortage of medicines and poor people suffering.”

The outburst was transmitted by video link from London, where Sharif, 70, is living on a medical release from prison in Pakistan. But the rally he addressed was in Punjab province, the stronghold of military influence and the nation’s wealthiest region, as well as the home of Sharif’s Pakistan Muslim League party.

The speech was not aired on any Pakistani TV channels, which have been under intermittent pressure from restrictive media laws and are always cautious about offending the military. But it circulated widely on social media and YouTube and was billed as the opening salvo in the opposition movement’s plans for a nationwide push against Khan and the army leadership.

“The army was always seen as more organized and resourceful than weak political parties, and people in Punjab joined it to bolster its forces. But what I am seeing now is totally different,” said Sarfraz Khan, a professor at the University of Peshawar who attended the rally in the city of Gujranwala.

“The middle class is widening and playing a bigger role in development,” he said. “They want the army to be confined to its institutional role so they can conduct business. They want democracy, peace and rule of law.”

Bajwa has not responded directly to Sharif, and he has previously stressed the importance of military deference to civilian rule. At a meeting of top army brass Tuesday, however, he was shown on news videos warning that the nation has “paid a heavy price to achieve peace and stability, and any attempt to destabilize the country will be met with a firm response.”

Imran Khan, in a speech Saturday, pointedly praised the army chief for providing emergency assistance during the coronavirus pandemic and devastating floods in Karachi. He also thanked troops for “sacrificing their lives” against aggression from rival neighbor India.

“The Pakistan army and General Bajwa are standing with us,” the prime minister declared. In the same speech, he dismissed Sharif as a “jackal” and hypocrite who had “polished the boots” of a former military dictator.

Pakistan’s current civilian and military leadership have jointly pledged to help settle the Afghan conflict and to rebuild the close strategic relations with the United States that were forged in a Cold War alliance and reactivated in an anti-terror partnership after the attacks of Sept. 11, 2001.

In recent years, U.S. and Afghan officials have accused Pakistan of harboring a Taliban branch called the Haqqani network, and the top Afghan Taliban leaders have long been based there. But lately, officials from both countries have sought Pakistan’s help in reducing Taliban violence and salvaging peace talks. The Taliban delegation to the talks in Qatar includes one member who was released from prison in Pakistan and another whose late father founded the Haqqani network.

Within Pakistan, it is unclear how much momentum the nascent anti-government movement can achieve. Khan may be vulnerable, having lost considerable popularity as the economy plummets and his ambitious social agenda falters. But the army has cracked down hard on previous resistance movements, notably a drive by minority Pashtun activists to expose repression against civilians in the restive northwest and a separatist movement by ethnic Baloch minority rebels in Baluchistan province.

There are also signs that some alliance members are not comfortable with Sharif’s anti-military diatribe. On Saturday, Bilawal Bhutto Zardari, chairman of the Pakistan People’s Party and son of slain former prime minister Benazir Bhutto, called the military establishment “part of history” and said it was “regrettable” that Sharif had mentioned any of its generals by name.

“We do not want their morale to go down,” he said of the armed forces. “We want a real and complete democracy, but we do not look to the umpire’s finger, we look to the people’s signal.”

Even Sharif’s outspoken daughter, Maryam, who lives in Pakistan and whose husband was arrested briefly Monday after the rally in Karachi, has stressed that she is not “anti-military.”

Hasan Askari Rizvi, a political analyst in Lahore, predicted that while the current confrontation could weaken Khan politically, it might actually increase the military’s influence.

“Traditionally, Pakistan has been a security state whose survival was the foremost concern,” Rizvi said. He noted that even today, “inefficient” civilian rulers continue to rely on the army for emergency and humanitarian interventions.

“The political forces were always weak and divided,” he said. “Now this division is getting wider, which will harm democratic institutions, too.”

Shaiq Hussain and Haq Nawaz Khan in Pakistan contributed to this report.