KABUL, Afghanistan – Stung by Afghan criticism of an airstrike that killed 18 civilians last week, the NATO force has agreed not to bomb residential buildings, a military spokesman said Sunday.

The agreement — reached Saturday night at a meeting between President Hamid Karzai and Gen. John Allen, the American who commands Western forces in Afghanistan — reflects a changing dynamic between the Afghan government and the NATO force.

As Western troops prepare to depart, Afghanistan has been more strongly asserting its sovereignty, in particular demanding curtailment of nighttime raids by special-operations forces.

Tensions had been building since last Wednesday’s deadly airstrike in Logar province, which came as coalition troops were targeting a Taliban commander in an overnight raid.

In response, Karzai cut short a trip to China the next day and sharply criticized the Western military effort during a visit to Kabul by Defense Secretary Leon Panetta.

On Friday, Allen took the unusual step of visiting Logar and apologizing to villagers, even though the military’s investigation is still ongoing.

Lt. Col. Jimmie Cummings, a spokesman for NATO’s International Security Assistance Force, said Western troops will continue to pursue insurgents who hide in residential compounds, “but when there is concern over the presence of civilians, air-delivered bombs will not be employed while other means are available.”

The presidential palace described the ban on more absolute terms, saying that Allen had “promised that from now on the NATO force will never bombard the people’s homes and villages, and that they will completely stop this act.”

Cummings said meetings would take place over the next few days to establish practices for involving Afghan army officers in decision-making on when and whether to employ airstrikes.