US air strikes early Thursday killed at least 30 Afghan civilians, including women and children, in the volatile northern province of Kunduz, officials said, after a Taliban assault left two American soldiers dead.

The strike triggered emotionally charged protests in the provincial capital, with the victims' relatives parading mutilated bodies of dead children piled into open trucks through the streets of Kunduz city.

The carnage underscores worsening insecurity after the Taliban last month overran the city for the second time in a year, as NATO-backed Afghan forces struggle to rein in the insurgents.

US-backed Afghan special operations forces were conducting an operation against the Taliban on the outskirts of the city when they came under insurgent fire, prompting calls for air support.

"In the bombardment, 30 Afghan civilians were martyred and 25 others were wounded," provincial spokesman Mahmood Danish told AFP.

Police spokesman Mahmoodullah Akbari gave the same toll, adding that the dead included infants aged as young as three months and other children.

Taza Gul, a 55-year-old laborer, was among dozens of angry protesters outside the Kunduz governor's office, bringing with him the bodies of seven dead family members in a motorized tricycle.

"I am devastated. I want to know why these innocent children were killed. Were they Taliban?" said Gul, breaking down in tears. "No, they were innocent children."

NATO said on Twitter that the air strikes were conducted by US aircraft.

"As part of an Afghan operation, friendly forces received direct fire and air strikes were conducted to defend themselves," Brigadier General Charles Cleveland, a senior spokesman for the NATO mission, said in a statement.

"We take all allegations of civilian casualties very seriously," he added, noting that NATO would help the Afghans investigate the incident, but he stressed it was an Afghan operation overall.

A US defense official, speaking on condition of anonymity, said "multiple" manned US planes were involved in the strikes, and they were targeted by small-arms fire from the ground.

Story continues

Civilian casualties caused by NATO forces have been one of the most contentious issues in the 15-year campaign against the insurgents, prompting strong public and government criticism.

Errant air strikes contributed to a 42 percent jump this year in casualties caused by pro-government forces compared to last year, according to the UN.

"Previous violations of international humanitarian law by US/NATO troops still remain uninvestigated and unpunished," Amnesty International said, condemning the Kunduz strikes.

"This cannot be another example of inaction in the face of such loss of life."

US State Department spokesman Mark Toner described the incident as a "terrible event."

- America's longest war -

Afghan President Ashraf Ghani said he was "deeply saddened" by the Kunduz killings, adding that insurgents were using civilians as human shields.

The strikes occurred after a firefight with insurgents killed two US soldiers and wounded four more. Three Afghan special forces were also killed during the anti-Taliban operation in Kunduz.

"On behalf of all of US Forces -- Afghanistan, today's loss is heartbreaking and we offer our deepest condolences," General John Nicholson, the top US and NATO commander in Afghanistan, said of the military losses.

"Despite today's tragic event, we are steadfast in our commitment to help our Afghan partners defend their nation," he added, without disclosing the names of the dead soldiers.

The killings come just days before the US presidential election.

During three lengthy debates between presidential candidates Hillary Clinton and Donald Trump, Afghanistan got scarcely a passing mention -- even though the situation there will be an urgent matter for the new president.

Either one will inherit America's longest war with no end in sight.

The US military, which leads a NATO mission to train and assist local forces after their combat mission ended in 2014, often gives upbeat assessments about Afghan military performance.

But as Afghan military forces near the end of a second year leading security operations without full NATO assistance, they are sustaining record casualties.

The Taliban's apparent strategic goal in 2016 is to seize another provincial capital like they briefly did in Kunduz last year, in a stinging blow to Afghan forces.

They have launched multiple assaults in recent months including in Kunduz, Lashkar Gar in poppy-growing Helmand province and Tarinkot, the capital of Uruzgan province.

The worsening conflict has prompted US forces to step up airstrikes to support their struggling Afghan counterparts, fueling the perception that they are increasingly being drawn back into the conflict.