More than 30 civilians were killed in US airstrikes on Thursday called in to protect Afghan and U.S. troops fighting the Taliban near the northern Afghan city of Kunduz, officials said.
Two US servicemen were also killed in fighting in the area.
Afghan officials said there was heavy fighting overnight in the village of Buz Kandahari, about 5 km (3 miles) from the center of Kunduz, which Taliban fighters succeeded in entering as recently as last month.
Air strikes called in to protect U.S. and Afghan special forces conducting the operation caused heavy casualties.
"Unfortunately more than 30 civilians, including women and children, were killed during the fighting. This was a horrible incident," said Asadullah Amarkhil, the governor of Kunduz, adding that dozens had been wounded.
There were angry protests by civilians who brought the bodies of many of the dead into Kunduz, which saw heavy fighting in early October.
In a statement, the U.S. military said the troops came under attack while working with Afghan partners to clear a Taliban position and disrupt the group's operations in the district around the city.
"As part of an Afghan operation, friendly forces received direct fire and air strikes were conducted to defend themselves," said Brigadier General Charles Cleveland, of the NATO-led Resolute Support mission.
"We take all allegations of civilian casualties very seriously."
In a statement, the Taliban said American forces were involved in a raid to capture three militant fighters when they came under heavy fire. An air strike hit the village where the fighting was taking place, killing many civilians.
The deaths underline the precarious security situation around Kunduz, which Taliban fighters came close to over-running last month, a year after briefly capturing it in their biggest success of the 15-year long war.
While the city itself was secured, the insurgents control large surrounding areas.
The U.S. military gave no details of the identity of the two personnel killed, their units or the circumstances of their deaths.
Although U.S. combat operations against the Taliban largely ended in 2014, special forces units have repeatedly engaged in fighting while assisting Afghan troops.
Masoom Hashemi, deputy police chief in Kunduz province, said police were checking if any of the dead had Taliban links.
Thousands of U.S. soldiers remain in Afghanistan as part of the Resolute Support training and assistance mission and a separate counterterrorism mission.
The deaths come a month after another U.S. service member was killed on an operation against Islamic State fighters in the eastern province of Nangarhar.
Afghan forces, fighting largely on their own since the international combat mission ended, have suffered thousands of casualties, with more than 5,500 killed in the first eight months of 2016.