Still, Admiral Kirby maintained on Tuesday that the insider attack, the first in months, would not change the Obama administration’s plans to leave a residual force in Afghanistan after most American forces are withdrawn at the end of the year and the NATO combat mission here formally concludes.

Admiral Kirby emphasized the progress that Afghan forces had made in recent years, citing as examples their role in limiting violence in the presidential election in April and the June runoff vote.

“They have had a good year, securing not one, but two, national elections and stopping or minimizing the impact of countless numbers of attacks throughout the country — even in Kabul,” he said.

Yet the shooting was a blunt reminder that discipline and vetting remain a challenge, and rogue Afghan soldiers and policemen remain a threat, despite a sharp drop in insider attacks since 2012, when the violence peaked and dozens of coalition service members were killed by Afghan counterparts.

With foreign troops having largely ceded their front-line role to Afghan forces in the past two years, training and advising Afghans is one of the few crucial roles still played here by the coalition. American soldiers largely stay out of the Taliban’s line of fire, but they must still maintain close contact with Afghan soldiers and policemen. Foreign forces have few options for protecting themselves, short of cutting off contact with the Afghans.

But that would make the training mission impossible, as General Greene, 55, most likely knew.

He was one of the most senior officers overseeing the transition from a war led and fought by foreign troops to one conducted by Afghan forces. His specialty was logistics — he was a longtime acquisitions officer — and he had been dispatched to Afghanistan to help the Afghan military address one of its most potentially debilitating weaknesses: an inability to manage soldiers and weaponry.