KABUL, Afghanistan  Nine boys collecting firewood to heat their homes in the eastern Afghanistan mountains were killed by NATO helicopter gunners who mistook them for insurgents, according to a statement on Wednesday by NATO, which apologized for the mistake.

The boys, who were 9 to 15 years old, were attacked on Tuesday in what amounted to one of the war’s worst cases of mistaken killings by foreign-led forces. The victims included two sets of brothers. A 10th boy survived.

The NATO statement, which included an unusual personal apology by the commander of the NATO forces in Afghanistan, Gen. David H. Petraeus, said the boys had been misidentified as the attackers of a NATO base earlier in the day. News of the attack enraged Afghans and led to an anti-American demonstration on Wednesday in the village of Nanglam, where the boys were from. The only survivor, Hemad, 11, said his mother had told him to go out with other boys to collect firewood because “the weather is very cold now.”

“We were almost done collecting the wood when suddenly we saw the helicopters come,” said Hemad, who, like many Afghans, has only one name. “There were two of them. The helicopters hovered over us, scanned us and we saw a green flash from the helicopters. Then they flew back high up, and in a second round they hovered over us and started shooting. They fired a rocket which landed on a tree. The tree branches fell over me and shrapnel hit my right hand and my side.”