Two U.S. service members, 26 civilians and three local troops were killed and four others were wounded Thursday during operations in Kunduz province, Afghanistan, military officials have said.

The service members, who will not be named until their families are notified, came under fire during a "train, advise and assist mission" with Afghan troops, U.S. Secretary of Defense Ash Carter said in a statement. They were working to clear a Taliban position and disrupt the group's operations in a Kunduz district.

"I was deeply saddened to learn overnight that we suffered casualties in Afghanistan. The two service members killed and the four who suffered injuries were with Afghan forces as part of our train, advise and assist mission. Some of our Afghan partners also died," Carter said. "Our service members were doing their part to help the Afghans secure their own country while protecting our homeland from those who would do us harm."

Gen. John Nicholson, the top U.S. commander in Afghanistan, said in a separate statement: "Our wounded soldiers are receiving the best medical care possible, and we are keeping them and their families in our thoughts today as well."

Afghan officials said they were still investigating the attack and its civilian casualties, some of which may have been caused by the airstrikes. Residents later carried more than a dozen corpses of the dead, including children, toward the local governor's office in a show of rage a year after American forces attacked an area hospital.

Two senior Taliban commanders targeted in the raid were also killed, along with 63 other insurgents, Kunduz police chief Gen. Qasim Jangalbagh said. He said Afghan special forces carried out the raid and that he did not have any information about NATO involvement in the assault.

The general identified the number of civilians killed, saying the count of 26 included members of the Taliban fighters' families.

Kunduz official Mohammad Yousf Ayoubi and parliament member Malim Chari both told The Associated Press that civilians were killed in the fighting, though they had few details. Dr. Mohammad Naim Mangal, the director of a Kunduz hospital, said his facility received the bodies of a dead man and a child and treated 30 people, including children, wounded in the fighting.

NATO only said it was "aware of the allegations," while the Pentagon did not immediately respond.

U.S. Brig. Gen. Charles Cleveland, briefing journalists in Brussels during a teleconference, said three Afghan troops were killed in the assault. Mohammad Radmanish, a deputy spokesman at the Afghan Defense Ministry, offered the same figure.

In a later statement, Cleveland said that "friendly forces received direct fire and airstrikes were conducted to defend themselves" and an investigation was underway.

He earlier described the assault as "not a common event," without elaborating.

Fighting has been fierce in Kunduz province, as Taliban fighters briefly overran the city of Kunduz — the provincial capital with the same name — in early October, a show of strength by the insurgents that also highlighted the troubles facing Afghan forces 15 years into the war there, AP reported.

The Taliban captured and held parts of Kunduz a year earlier as well before the city was liberated weeks later with the help of U.S. airstrikes, AP reported.

Since the U.S. transferred the lead for combat operations to Afghan forces in 2014, the number of American combat deaths there has declined. So far this year there have been at least four other combat deaths among American forces, AP reported.

Jon Gambrell and Amir Shah of The Associated Press contributed to this report. Ap writer

Lorne Cook in Brussels also contributed.