Discuss as:

Obama apologizes to Afghanistan over Quran burnings; 2 US troops shot dead

Shah Marai / AFP - Getty Images

Afghans shout anti-American slogans during a protest in Kabul on Thursday.

Updated at 9:50 a.m. ET: KABUL, Afghanistan -- President Barack Obama has written a letter to his Afghan counterpart apologizing for the burning of copies of the Quran at a NATO military base in the country. Two U.S. soldiers were also shot dead Thursday at a protest about the desecration of the holy books.

A man wearing an Afghan government soldier's uniform killed the American troops and wounded four others at the demonstration in Nangarhar province, officials told NBC News.

There have been violent protests daily since it emerged on Tuesday that Qurans used by detainees held at the Bagram military base had been burned. The incident has become a public relations disaster for foreign forces in Afghanistan.

A statement from President Hamid Karzai's office said the U.S. ambassador to Afghanistan had delivered the letter from Obama Thursday.

Taliban to Afghans: Kill foreigners over Quran burnings

In the letter, which is quoted in the statement, the U.S. president expressed his "deep regret for the reported incident" and offered his "sincere apologies."

According to the statement, Obama wrote: "The error was inadvertent; I assure you that we will take the appropriate steps to avoid any recurrence, to include holding accountable those responsible."

Massoud Hossaini / AFP - Getty Images

Angry afghans attacked U.S. bases after reports of Quran desecration.

Tommy Vietor, a spokesman for the National Security Council, told NBC News that Obama had "expressed our regret and apologies over the incident in which religious materials were unintentionally mishandled at Bagram air base."

The Quran burnings at the vast Bagram base could make it even more difficult for U.S.-led NATO forces to win the hearts and minds of Afghans and bring the Taliban to the negotiating table ahead of the withdrawal of foreign combat troops by the end of 2014.

Muslims consider the Quran the literal word of God and treat each book with deep reverence. Desecration is considered one of the worst forms of blasphemy.

NBC's Afghanistan correspondent discusses the Quran controversy

General John Allen, commander of the International Security Assistance Force (ISAF), on Tuesday offered his "sincere apologies" for the burnings. "When we learned of these actions, we immediately intervened and stopped them," he added. "This was not intentional in any way." 

The deadly protest in Nangarhar was one of several across the country on Thursday.

Riots triggered by the inadvertent Quran burning at a U.S. military base prompted the U.S. to lock down its embassy. NBC's Atia Abawi reports.

According to Haji Mohammad Hassan, the deputy police of Khogayani district in Nangarhar province, American soldiers had starting firing at protesters who were attacking their base.

He said that an Afghan soldier then turned his weapon on the U.S. troops, shooting six, killing two and injuring four.

PhotoBlog: 'Death to America!' Afghan anger over Quran burning intensifies

Hassan said the Afghan soldier escaped by joining the crowd of protesters. However, a provincial official, who asked not to be named, said the shooter had been killed after the attack.

The Taliban have claimed responsibility for the attack, NBC News reported. 

Taliban spokesman Zabiullah Mujahid said in a text message that they infiltrated the army with one of their fighters who had shot and killed the Americans. Mujahid claimed that their insurgent killed 10 Americans.

More from msnbc.com and NBC News:

The Associated Press, Reuters, NBC News' Atia Abawi, Chuck Todd and Kristen Welker contributed to this report.