— As thousands of angry Afghans flung rocks at NATO’s largest military base in Afghanistan on Tuesday, American officials sought to quell a widening furor over what they said was the accidental incineration by U.S. military personnel of copies of the Islamic holy book.

The protests erupted early Tuesday after Afghans working at Bagram air base told local residents that a number of copies of the Koran had been burned. When they carried out the charred pages, waving them in the air, the crowd grew larger and more defiant.

Among those chanting “Long live Islam” and “Death to America” were some of the 5,000 Afghans who have worked inside the base for years. Gen. John R. Allen, the top U.S. commander in Afghanistan, was quick to express contrition for the incident, which officials worried could incite violence across the country.

U.S. officials said the books were mistakenly sent with a pile of trash for disposal before several Afghans identified them. Although the initial protests were concentrated largely around the Bagram base, some of the charred Koran remains were sent promptly to Kabul, where President Hamid Karzai and other top Afghan officials will decide how to respond to the incident.

“These people must be punished,” said Qari Ghulam Mustafa, a top religious official from Parwan province, where Bagram is located. He carried a stack of 10 blackened Korans on his lap as he and others traveled to the capital in a white hatchback. He said nearly 100 more publications were damaged.

“If the Americans ever deny that they did this, we will show them these pages,” said Mullah Abdul Rahim Shah Agha, the head of the Parwan ulema council, or Muslim clerical body.

The apologies from Allen and top Obama administration officials were among the most profuse of the decade-long war. But there was no immediate indication that they would calm the kind of unrest that has turned explosive in the past, notably in April, when deadly protests broke out over a case of Koran-burning in Florida.

“When we learned of these actions, we immediately intervened and stopped them,” Allen said in a statement. “We are taking steps to ensure this does not ever happen again. I assure you . . . I promise you . . . this was NOT intentional in any way.”

The United States faces an enormous challenge in withdrawing its troops over the next two years while attempting to protect hard-won gains and facilitate a delicate peace process between the Afghan government and Taliban insurgents. With so little margin for error, the incident Tuesday could threaten the relationship on which U.S. military and diplomatic strategies depend.

U.S. and Afghan officials expressed concern about the prospect of more violent reaction in coming days.

The U.S. Embassy in Kabul warned American citizens, “Past demonstrations in Afghanistan have escalated into violent attacks on Western targets of opportunity.”

The incident also could complicate relations between NATO forces and those Afghans who perform a variety of nonmilitary functions on bases. The hundreds of Bagram employees who were among the protesters will have to decide whether to leave their jobs or continue working while disguising their antipathy.

“The people who do this are our enemies,” said a 27-year-old who has worked at a warehouse on the base for two years. “How could I ever work for them again?”

Another Bagram employee who joined the protest said, “Whoever goes back to work will be killed. They’ll think of us as traitors.” The workers declined to give their names for fear of reprisals.

More than 3,000 people were involved in the protests Tuesday. Afghan and Western security forces blocked roads leading to the base and instructed local employees to stay home. But when they heard about the incident, the workers arrived at the base’s front gate in droves.

Rumors about the incident — and American motives — circulated through the crowd. In Kabul, 35 miles to the south, even top Afghan officials struggled to understand what had happened.

Gen. Ahmad Amin Naseeb, director of the Afghan army’s religious and cultural affairs department, said he had been told “that the international troops have burned and thrown copies of the Koran into the dustbins.”

In his second statement of the day, Allen announced that all NATO forces in Afghanistan would complete training in the proper handling of religious materials by March 3.

NATO said religious materials, including Korans “identified for disposal,” were collected at the Parwan Detention Facility, a prison next to the base, and “were inadvertently taken to an incineration facility at Bagram airfield” Monday night.

A senior U.S. military official said the Korans were removed from the prison library because they had radical or inflammatory messages scrawled in them. A Western official, speaking on the condition of anonymity, told the Associated Press that the texts were charred but that none were destroyed.

Proper treatment of the Koran is a highly sensitive issue for Muslims across the world, including in Afghanistan, where international troops are fighting to defeat the militantly Islamist Taliban in a war that has entered its 11th year. Experts in Islam say copies of the Koran should be buried or released in flowing waters if they need to be disposed of, but religious leaders in Afghanistan said Tuesday that local practice is not to dispose of the texts at all.

In Washington, White House spokesman Jay Carney echoed Allen’s apology, saying: “We apologize to the Afghan people and disapprove of such conduct in the strongest possible terms. This deeply unfortunate incident does not reflect the great respect our military has for the Afghan people. It’s regrettable.”

Staff writer Greg Jaffe in Washington and special correspondents Sayed Salahuddin and Walid Fazly in Kabul contributed to this report.