KABUL, Afghanistan — A joint U.S.-Afghan raid Thursday against the Taliban involving NATO airstrikes left 26 civilians and three Afghan troops dead in Kunduz province, Afghan officials said. Two U.S. soldiers were killed in a separate ground clash there as investigators worked to determine what went wrong.

The Americans killed and four other U.S. troops wounded were among military advisers helping Afghan troops, rare combat casualties for Western forces who handed over the task of securing Afghanistan to local troops two years ago.

Afghan officials said they were investigating the attack and civilian casualties, some of which may have been caused by airstrikes called in to support Afghan and U.S. troops under fire.

Residents later carried over a dozen bodies toward the local governor's office in a show of rage a year after American forces attacked an area hospital.

NATO declined to identify the Americans killed, pending notification of next of kin.

“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,” Defense Secretary Ash Carter said in a statement.

The targets of the raid were two senior Taliban commanders, who were killed in the fighting 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.

Jangalbagh said 26 civilians, including members of the Taliban fighters' families, were killed in the assault.

U.S. Brig. Gen. Charles Cleveland said during a teleconference in Brussels 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.”

A Taliban statement also said there were civilian casualties while claiming its fighters killed 16 U.S. troops. The insurgents often exaggerate their battlefield successes.

According to defense officials, the U.S. Army soldiers had gotten off a helicopter and were moving on foot with Afghan forces doing clearing operations in Kunduz province.

The defense officials said the troops came under fire and returned fire, but it wasn't clear whether it was gunfire or other larger rounds. Two of the U.S. troops were killed and four others were injured. Two of the injured had more serious wounds and were taken away by medevac.

The officials said the troops called for support, and the U.S. launched airstrikes. They said they believe the troops were hit by enemy fire and were not killed or injured by the airstrikes. All of the U.S. troops were evacuated from the area.

Afghan President Ashraf Ghani issued a statement criticizing the Taliban for using women and children as “a shield” during the raid. He also announced a local investigation had been started.

Also Thursday, Afghan officials said a roadside blast struck a group of people on its way to a wedding in the northern Faryab province, killing at least nine civilians and wounding 11.

Javed Dedar, a spokesman for the provincial governor, said the bride was among those wounded. It remained unclear if the blast was caused by a roadside mine or mortars fired by militants, and the remote location of the incident made the details difficult to verify.

NATO's combat operations ended in Afghanistan at the end of 2014, a move that put Afghan forces in charge of the country's security. Since then, Afghan forces have suffered heavy casualties battling the Taliban.

The Washington Post contributed.