ISLAMABAD, Pakistan — The most popular man in public office in Pakistan does not give speeches on television, rarely appears in public and rejects news interviews.He is Gen. Raheel Sharif, the Pakistani Army chief, who has presided over the country’s armed forces at a time when they are riding high after curbing domestic terrorism and rampant political crime.

Aided by a new-media publicity campaign, the military command’s popularity has helped it quietly but firmly grasp control of the governmental functions it cares about most: security and foreign affairs, along with de facto regulatory power over the news media, according to interviews with Pakistani officials and analysts.

In a country with a long history of military coups, the current command has gotten what it wants, edging aside the civilian government of Prime Minister Nawaz Sharif, who is not related to General Sharif, without the messiness or the international criticism a complete takeover would bring. And it is being thanked for doing it.

“I wouldn’t describe it as a soft coup, but I would definitely say the civilian leadership has yielded space to the military — for their own survival and because there were major failures on their part,” said Talat Masood, a retired lieutenant general and military analyst.

General Sharif, known as General Raheel here, took over the military command late in 2013. He was appointed to the post a few months after the new civilian government was inaugurated, and the country was in trouble. There were suicide bombings, political party killings, rampant crime and violence in its big cities, and assassinations of political leaders. Some politicians were calling for negotiations with the Pakistani Taliban as military efforts to set the militants back appeared to have stalled.

Then the Pakistani Taliban carried out a cruel attack on a school for army families in Peshawar last December, killing 145 people — including 132 schoolchildren methodically gunned down in their classrooms. Supported by a huge public backlash against terrorism, the army ramped up its crackdown on some of the militant groups sheltering in the country’s northwestern tribal areas, especially in North Waziristan.

Capital punishment was restored, and the military was handed new power, starting its own counterterrorism court system alongside the badly backlogged and compromised civilian justice system.

This year, the Pakistani Taliban have managed to carry out only a single major suicide bombing. The army’s success against the Taliban emboldened it to take on violent political parties and criminal gangs in the country’s biggest city, Karachi, through a paramilitary group known as the Sindh Rangers. Despite complaints of human rights abuses in Karachi, and millions of internally displaced people from the tribal areas, most Pakistanis were simply relieved to see the violence hugely reduced.

Through it all, General Sharif’s public appearances have been less ostentatious than those of some of his predecessors. But at the same time, his face has become ubiquitous on social media, after giving a free hand to the officer commanding the Inter-Services Public Relations office, the military’s media arm, to modernize that service.

The ISPR had long been headed by lower-ranking officers, and it remained decidedly lodged in the analog era. But by this year, the leader of the office, Asim Saleem Bajwa, had been promoted to lieutenant general — a three-star rank normally reserved for corps commanders — and his agency had become an impressively slick machine.

General Bajwa’s Twitter account has more than 1.5 million followers, and the agency’s Facebook account has more than 2.8 million likes. A film division is pumping out offerings for television, as it had long done, but it has added short videos tailored to YouTube-style platforms.

he social media accounts show in daily detail the commander’s movements — visiting the front lines in Waziristan or reviewing troops. Video links showed army units in combat, sometimes the same day it occurred, and troops helping earthquake victims. Professionally produced martyr-style videos show, for instance, a mother mourning a son killed in the field, who returns from the dead to present her with his beret.

The ISPR declined to comment for this article unless a draft of it was submitted to the office for advance review, according to a spokesman for the agency.

The Pakistani news media is clearly reflecting the shift in influence. When Prime Minister Sharif visited Washington on Oct. 22, for instance, the visit did not get nearly the attention of General Sharif’s current five-day visit to Washington.

In recent weeks, General Sharif has seemed less circumspect about the new pecking order. The military press office noted, for instance, that at a meeting of army corps commanders last Tuesday, the general was “concerned” that the civilian government was not doing enough to follow up the military’s success at clearing out the frontier areas with effective governance. The clearly implied scolding sent shock waves through the political establishment, but few dared to criticize the military — something even opposition parties rarely do now.

The Pakistani news media, in particular, has largely stopped open questioning of the military’s increased power. Pakistani journalists say the military no longer has to bring intimidation to bear, as it long had, because most of the criticism has gone quiet. At the military’s insistence, a government watchdog body has ordered broadcast media to stop airing anything that could be viewed as support for terrorist groups — a notably broad definition.

Even some of the military’s critics in the news media now say the relative peace has been a trade-off nearly everyone supports.

“My honest opinion is that most of the pressure now is from within ourselves,” said Rana Jawad, the news director at GEO, a leading private television network. “One of the reasons why there’s no effort to counter the claims of ISPR is that the situation on the ground has improved drastically. It’s a big thing for me: I used to report on 50 dead, 40 dead, 30 dead almost every day, and there’s nothing of this sort now.”

Mr. Jawad is no apologist for the military, however. He was on a cellphone call in 2014 with the channel’s news anchor in Karachi, Hamid Mir, when an attacker shot Mr. Mir six times. “It was terrible; I could hear his screams and helplessness and the shots,” Mr. Jawad said.

GEO journalists blamed the military’s powerful intelligence arm, the Inter-Services Intelligence agency, and the channel even broadcast a picture of the agency’s leader at the time, Lt. Gen. Zaheer ul-Islam, which some saw as an implication that he had been behind the attack. That led to legal action against the channel that continues, and some local cable operators have refused to carry GEO.

“We suffered a lot from the military,” Mr. Jawad said. “We were beaten, hounded, brought to our knees by the powerful military, so we know.” Nonetheless, he added: “I see a marked improvement in the security environment in Pakistan, fewer and fewer Pakistanis dying unnecessarily, and I cannot reject this.”

The military’s triumphant crackdown on militants has had little effect on the war next door in Afghanistan, however, and the command still appears to be playing a double game when it comes to using some militants as proxies.

In particular, military analysts said, the pressure does not extend to the Afghan Taliban, many of whose leaders live openly in the Pakistani city of Quetta. And the military has avoided tangling with the Haqqani network, a close Afghan Taliban ally whose members have carried out some of the deadliest attacks in Afghanistan but are mostly based in remote districts of Pakistan near the border.

The double standard led to the blocking of one American military aid payment of $300 million to the Pakistani military this year, under a congressionally mandated requirement to certify progress in fighting the Haqqanis. An additional $1 billion in military aid under a separate program this year was not affected by that requirement, however.

Amid the Pakistani command’s clearly ascendant streak, Mr. Masood, the military analyst and former lieutenant general, worries that the military may go too far, preventing the country’s still-immature democratic institutions from developing.

“Success speaks for itself. They did clear Waziristan, and General Sharif does get credit for that,” he said. “But success can change. If they overplay the military card and continue to build an inflated image, it could boomerang. They need to allow civilians their space. But I’m afraid the lust for power is such that they don’t always understand that.”

"What Julia Child did for French cooking, Pundita is doing for foreign policy discussion. She's opened a haute pursuit to ordinary people." - Caesar Rodriguez

"Few bloggers think as deeply as Pundita does. And few have her foresight." - Uppity Woman

"There is no other blogger like Pundita. She has carved a niche - part history and part humint - that makes any essay of hers a thing unto itself. In addition there are the sparkles of her dry wit sprinkled through her work." - Dymphna, Gates of Vienna