Nangarhar, which borders Pakistan, has faced mounting security perils over the past couple of years, with new Islamic State affiliates complicating the threat from the Taliban. Zabihullah Zmarai, a member of the provincial council, said the Islamic State posed a danger in five districts, despite repeated operations by the Afghan Army.

“Out of the 22 districts, only six are secure,” he said.

The Taliban’s presence across nearly a dozen districts varies, Mr. Zmarai said. But the Hisarak district faced a collapse in recent weeks. That drew the attention of General Zahid, who had gone there to supervise a counterattack.

Over the past decade, he rose from a bodyguard to a well-regarded police chief of several volatile provinces. His postings included two stints as the police chief of southeastern Ghazni Province, and one term each in Zabul and Paktika Provinces.

General Zahid was seen as a hands-on commander, often arriving at the front lines unannounced. When a major cultural event drew world leaders to the ancient city of Ghazni, the general was photographed riding around the city on the back of a motorcycle to check on security measures. He had been wounded twice and had lost two brothers during the decades of war in Afghanistan.