A NATO helicopter crashed during a battle with the Taliban in Afghanistan, killing 31 U.S. soldiers and seven Afghans, the Afghan president said on Saturday, the deadliest single incident for foreign troops in 10 years of war.

A brief statement from the presidential palace said the troop-carrying Chinook helicopter had crashed in Syedabad in central Maidan Wardak province, just west of the capital, Kabul.

It identified the Americans as special forces troops.

The Taliban quickly claimed to have shot down the helicopter during a firefight, although the Islamist militant group often exaggerates incidents involving foreign troops or Afghan government targets. They also said eight insurgents were killed in fierce fighting.

"They wanted to attack our mujahideen who were in a house, but our mujahideen resisted and destroyed a helicopter with a RPG (rocket-propelled grenade) rocket," Taliban spokesman Zabihullah Mujahid said by telephone from an undisclosed location.

"Eight mujahideen were martyred and 38 Americans were killed and today they (U.S. soldiers) carried away parts of their plane and shattered pieces of their bodies."

U.S. and NATO-led International Security Assistance Force (ISAF) officials in Kabul confirmed a helicopter had crashed on Friday night but gave no details about casualties or the possible cause.

"ISAF is still assessing the circumstances that resulted in these deaths and recovery operations are currently underway," the U.S. embassy in Kabul said in a statement.

Defense Secretary Leon Panetta said in a statement the United States would "stay the course" to complete the mission in Afghanistan, a sentiment echoed by NATO Secretary General Anders Fogh Rasmussen.

"The incident is under investigation right now as this helicopter belongs to international forces," Afghanistan's Defense Ministry spokesman Zaher Azimy told Reuters television.

"Obviously they will provide details of the crash and the reason."

He said the Afghans killed were also from a commando unit.

Afghan President Hamid Karzai "shared his deep sorrow and sadness" with his U.S. counterpart, Barack Obama, and the families of the victims, the palace statement said.

The deaths come two weeks after the start of a gradual security handover from foreign forces to Afghan troops and police, and at a time of growing unease about the increasingly unpopular and costly war.

The helicopter crash will likely raise more questions about the transition process and how much longer troops should stay. All foreign combat troops are due to leave by the end of 2014, but some U.S. lawmakers question whether that is fast enough.

The crash was the deadliest incident of the war for foreign troops. In April 2005, another CH-47 Chinook crashed, killing 15 U.S. servicemen and three civilian contractors. Another Chinook crash in June of the same year killed 17 U.S. troops.

PRICE TO PAY

U.S. and other NATO commanders have claimed success in reversing a growing insurgency in the Taliban's southern heartland, although insurgents have demonstrated an ability to adapt their tactics and mount attacks in other areas.

Any gains against the Taliban have come at a high price, with 711 foreign troops killed in Afghanistan in 2010, the deadliest year of the war since the Taliban were toppled by U.S.-backed foreign troops in late 2001.

The crash in Maidan Wardak, where the majority of foreign troops are American, means at least 375 foreign troops have been killed so far in 2011. More than two-thirds were American, according to independent monitor www.icasualties.com and figures kept by Reuters.

Another three ISAF soldiers were killed in the south over the previous 24 hours, the coalition said.

CIVILIAN TOLL

Earlier on Saturday, Afghan police said a NATO air strike killed eight civilians in the Nad Ali district of southern Helmand province on Friday.

Nad Ali district police chief Shidi Khan said the air strike was called in after insurgents attacked ISAF troops in the area. Those killed in the strike were members of a family that had fled fighting in neighboring Uruzgan province, police said.

ISAF confirmed there had been an air strike in the district and said it was investigating whether civilians had been present at the time. It said it had received reports civilians were being held hostage by insurgents.

Civilian casualties caused by foreign troops hunting Taliban fighters and other insurgents have long been a major source of friction between Kabul and its Western backers.

Despite the growing military toll, Afghan civilians have continued to bear the brunt of the war, with casualties hitting record levels in the first half of this year.

A U.N. report last month said 1,462 civilians were killed in conflict-related incidents in the first six months of 2011, up 15 percent on the first half of 2010. It blamed insurgents for 80 percent of those deaths.

Helmand province, where the Taliban still dominate several districts, has been the scene of some of the most vicious fighting of the war and far more foreign troops have died there than in any other province. Its capital Lashkar Gah was the most contentious of the first seven areas to be handed over.

In the past month, insurgents have carried out a string of assassinations of high-profile southern leaders, including Karzai's half brother, and several large attacks which have killed police and civilians.