One of the precautions instituted as a result, Afghan officials said, was that the guards were allowed to carry weapons only when on duty and could not take them home or carry them to and from work. They also were not allowed to live on the base, a privilege now restricted in most cases to non-Afghan personnel.

The guards killed Monday night lived in the small village of Kotwali, about six miles from the base, and they would have been paid about $250 a month each, more for supervisors. None could afford to own a car. Ten of them joined forces to pay the $300 monthly rent for a station wagon for the trip to work every day, typically with two people riding in the front seats, four in the back seats, and four others crammed into the rear luggage compartment.

On Monday night, their shift at Bagram was scheduled to begin at 10 p.m., and at 9:45 they reached the village of Shahka, less than two miles from the base, where a Taliban ambush was waiting for them, the Afghan police said. An unarmed man stepped into the road, and when the car stopped, he looked inside, said, “This is them,” and ducked out of the way. Two armed Taliban on either side of the road opened fire on the car with automatic weapons, according to Zaman Mamozai, the Parwan Province police chief. “The driver made a mistake,” Mr. Mamozai said. “He never should have stopped the car for the unarmed man.” He said an investigation was underway to determine who in the village had told the Taliban about the guards.

Malik Abdul Jabbar, the village chief in Kotwali, said he lost three relatives: a nephew, Shamsuddin, 28, who had three children; a cousin, Mohammad Aman, 50, who had 10 children; and another cousin, Mohammad Usman, 40, who had seven children. “If they were inside the base, it would have been more secure for them, but Americans are not allowing Afghans inside the base,” Mr. Jabbar said.

Last year’s mass firings at the base have had a huge economic effect on the surrounding area, since it was by far the biggest employer in the province, other than the agricultural sector. Mohammad Asif, the Bagram deputy district governor, said the Americans’ suspicions had caused resentment in the area, which in turn risked feeding the insurgency. “Sometimes it makes one say, based on the principles of Islam, may God banish them from this land,” Mr. Asif said.

In addition to the attack Monday night, a scattering of rockets and mortars have struck the Bagram base itself, according to Afghan officials, although most did not cause casualties.