Pakistani army chief General Raheel Sharif attends a change of command ceremony in Resolute Support headquarters in Kabul, Afghanistan, March 2, 2016. ( POOL New / Reuters/REUTERS)

— The news came in a brief, bland-sounding tweet from the army public relations office this past week, noting that Gen. Raheel Sharif, Pakistan’s popular army chief, was beginning a round of “farewell” visits to military units across the country. 

But the subtext of the message was monumental. It meant that for the first time in 20 years, the most powerful official in Pakistan — a U.S. Cold War and anti-terrorism ally in which generals have often interfered in civilian rule — was keeping his pledge to retire on time and turn over his job to a successor chosen by the prime minister. 

On Saturday, Prime Minister Nawaz Sharif announced that he had named Gen. Qamar Javed Bajwa, a career infantry officer, to replace Gen. Sharif, ending weeks of intense speculation over which of the four shortlisted generals he would pick to run the army for the next three years. 

The prime minister passed over three more senior generals in appointing Bajwa, who serves as an inspector general at army headquarters. Analysts said ­Bajwa has strong pro-democracy views and might be more open to civilian involvement in foreign and security policy than past army chiefs. The appointment was quickly welcomed by numerous civilian leaders. 

But in many ways, the fact that Gen. Sharif was bowing out on time — and will pass his bamboo swagger stick to Bajwa in a formal military ceremony on Wednesday — mattered even more.

Despite Sharif’s reputation as a professional with no political ambitions, his departure after a three-year term had not been a foregone conclusion. In recent months, as opposition protests erupted, tensions with next-door India escalated and Prime Minister Sharif (no relation) battled charges of hiding money overseas, some influential figures urged the army chief to stay on and keep things from spinning out of control. 

It was a familiar temptation that has repeatedly kept Pakistan from evolving as a democracy in the name of safeguarding its stability. The fact that Gen. Sharif resisted, analysts said, matters far more than the recent frenzy of drawing-room and barracks speculation over who will replace him.

“Some of the hyper-nationalists, some TV anchors and retired [military] mafia wanted him to stay, but he disappointed them,” said Saad Mohammed, a retired brigadier general. “He stayed out of politics, he stood up to India, he brought the army out of despondency and he took on the challenge of terrorism that was eating at our vitals. He will go down in history as one of our best and most popular army chiefs.”

As Sharif, 60, prepared to step down Wednesday, the shower of praise came from all quarters, including the hashtag #ThankYouRaheelSharif that went viral. This send-off contrasted sharply with the departure of Gen. Pervez Musharraf, who seized power in 1999, while Nawaz Sharif was also premier, and clung to it until forced out by protests a decade later.

Musharraf’s successor, Gen. Ashfaq Kayani, requested and was granted an extra three-year term by Prime Minister Yousaf Raza Gillani in 2010, amid a struggling campaign against violent Islamist militias.

This time, Prime Minister Sharif seemed so confident that, after a dinner Thursday at which he praised Gen. Sharif as “one of the finest military leaders of his generation,” he left Pakistan on Friday for a meeting in Turkmenistan, and named Bajwa as soon as he returned Saturday. 

Still, critics said that the ­civilian-military power balance remains extremely lopsided and that Pakistan’s security agencies will continue to control foreign and military policies. After Prime Minister Sharif took office in 2013, he sought to improve trade with archrival India but then backed off under military pressure amid rising tensions over the disputed Himalayan territory of Kashmir. 

These days, after deadly border incidents in Kashmir that have brought relations between the neighboring nuclear powers to their worst point in years, the mild-mannered premier has scrambled to sound as tough on India as Gen. Sharif, who vowed to “defend every inch of our beloved country” after India claimed it had launched a “surgical strike” on Pakistan in September.

Senate Chairman Raza Rabbani, speaking at a seminar Thursday, declared that civil-military relations are still the “biggest challenge to democracy” and that wealthy pro-military interests “will not accept a civilian supremacy.” While noting that Pakistan’s legislature is often labeled as a corrupt “debating club,” he added, “I am one of those who believe the worst form of democracy is better than dictatorship.”

Today, though, the military’s luster is the brightest it has been in years, especially since Gen. Sharif’s successful Zarb-e-Azb campaign last year to drive Islamist militants from the northwestern tribal region. That effort, launched by Kayani, was delayed by political ambivalence and troop resistance to fighting fellow Muslims. But attitudes shifted with an increase in atrocities, especially a 2014 terrorist massacre at an army public school that left 141 students and teachers dead.

“This is not the army of the 1990s, when nobody dared call the Taliban enemies,” said Zahid Hussain, a journalist and author. “It is war-hardened. It has seen soldiers with their throats slit and their heads used as footballs. They still don’t trust the civilians, but they are much more motivated to fight the militants.”

Some warn that the army’s recent success, coupled with Gen. Sharif’s outgoing personality, risks reviving a military hero-worshiping tendency in Pakistani society that has weakened civilian leadership during the country’s 70-year history. There have been several efforts to promote Sharif as a field marshal or candidate for president after he retires.

But Muhammad Amir Rana, director of the Pak Institute for Peace Studies, said even a smooth transition from one military boss to another “will not help resolve civilian-military issues. The balance will remain in the military’s favor because civilian institutions continue to suffer from a lack of moral and political legitimacy,” he said.

Most observers said they expect few changes in military policy, which is consumed by Pakistan’s rivalry with India, the domestic fight against Islamist militancy and an ambivalent relationship with insurgent-plagued Afghanistan.

While the nation was clearly grateful for the departing chief’s service, it was also relieved to see him go. As the editors of Dawn newspaper noted, the cascade of recent crises brought “opportunity after opportunity” for Sharif to reconsider, “but good sense has prevailed, and a good officer can be given a fond and formal farewell.”

Shaiq Hussain in Islamabad contributed to this report.