Two U.S. service members were killed Thursday during a joint raid by U.S. special operations forces and Afghan troops targeting senior Taliban commanders -- rare combat deaths for Western forces who handed over the task of securing Afghanistan to local troops some two years ago.

Defense Secretary Ash Carter said he was "deeply saddened" to learn of the American deaths, adding that four U.S. service members suffered injuries. More than 30 Afghan civilians were killed in the fighting as well, according to local reports.

The American service members “came under fire” alongside Afghan troops while attempting to “clear a Taliban position” in Kunduz province, military officials said.

AMERICAN AIRSTRIKE IN SYRIA KILLS AL QAEDA LEADER LINKED TO BIN LADEN, PENTAGON REPORTS

U.S. airstrikes were called in during the firefight but Afghan forces were leading the assault, Fox News has learned.

At least five Americans have been killed in action in Afghanistan since early October.

"Today's loss is heartbreaking and we offer our deepest condolences to the families and friends of our service members who lost their lives today," Gen. John W. Nicholson, commander of U.S. Forces-Afghanistan, said in a statement.

A U.S. defense official told Fox News that the incident occurred last night local time, but declined to give any more details.

IRAN'S SUPREME LEADER CRITICIZES TRUMP, CLINTON



The target of the raid appeared to be two senior Taliban commanders killed in the fighting among 65 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.

U.S. officials did not immediately identify the service members who died. The Pentagon reported it would investigate some Afghans' accusations the U.S. military killed innocent people in the airstrikes.

The news came days after the Pentagon announced it targeted top Al Qaeda leaders in Afghanistan on Oct. 23, Faruq al Qatani and Bilal al Utabi.

The U.S. military has not confirmed the deaths of Qatani and Utabi, though officials say they were likely killed in drone strikes which involved multiple Hellfire missiles launched at separate compounds housing the terrorist leaders.

Officials say Al Qaeda continues to plan attacks against the United States from the mountains of eastern Afghanistan.

There are roughly 10,000 U.S. troops remaining in Afghanistan 15 years after the 9/11 attacks. 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.

The number is supposed to go down to 8,400 by the time President Obama leaves office in January. When Obama announced the end of the combat mission in Afghanistan at the end of 2024, the original plan was to leave 1,000 troops to guard the U.S. embassy in Kabul.

Kunduz has been the scene of many Taliban attacks in the past year. A year ago, a U.S. Air Force AC-130 gunship mistakenly attacked a Doctor's Without Borders hospital in the city of Kunduz killing at least 42 and injuring dozens more while battling the Taliban for control of the city.

The Taliban and Afghan government recently held secret talks to see if they could start peace negotiations to end the fighting, though questions remain over which faction of the insurgency is doing the talking.

Fox News’ Lucas Tomlinson and The Associated Press contributed to this report.