Afghan protesters shout anti-U.S. slogans during a protest in Kunduz province. Four people were shot dead by Afghan security forces on Saturday as protests over the burnings of the Muslim holy book at a NATO base erupted for a fifth day, with an attempt by demonstrators to bombard a U.N. compound in the north. (Reuters)

The top U.S. commander in Afghanistan on Saturday recalled all NATO personnel working in Afghan ministries in the Kabul area — a bold and potentially divisive response to the killing of two American service members by an Afghan security official in the country’s fortified Interior Ministry earlier in the day.

Marine Gen. John R. Allen’s directive comes five days after U.S. military personnel burned a pile of Korans at the largest military base in Afghanistan in an apparently inadvertent act that set off violent protests across the country. More than 25 Afghans have died in those demonstrations, and four NATO soldiers have been killed by men wearing Afghan security uniforms since Thursday, when the Taliban urged Afghan soldiers and police to turn their weapons on their Western counterparts.

The week’s events have exposed a core vulnerability of the Obama administration’s strategy for winding down the decade-long Afghan war: a fraying trust between two presumed allies who must depend on each other to keep the insurgency at bay.

Although mutual suspicions have been building for some time, the Koran burnings followed by the apparent revenge killings of U.S. military personnel will make it much harder for both sides to agree in the coming weeks on the specific terms and timetable of NATO’s planned withdrawal from Afghanistan by the end of 2014.

NATO leaders are scheduled to hold a summit in May in Chicago, where they had hoped to finalize details of the withdrawal and the gradual handover of security responsibilities to Afghan forces, as well as report progress in fledgling negotiations with the Taliban.

But inflamed public anger among all sides could force a reassessment of those plans. Afghan patience is wearing thin with repeated acts of cultural insensitivity by foreign troops. Meanwhile, Americans and Europeans are growing increasingly resentful of the mounting number of treacherous attacks by Afghan forces they are trying to train.

The escalating tension here prompted apologies for the Koran burning from President Obama and several top U.S. defense officials. But demonstrations continued unabated Saturday, even before U.S. officials reported that an Afghan security officer had killed an American colonel and major in one of Kabul’s most important and most impenetrable ministries.

The two men, whose names have not been released, were shot in the back of the head while working at their desks.

Within hours of the attack, Allen recalled Western advisers from Afghan ministries, citing “obvious force protection reasons.” The decision will affect several hundred officials who work with the Afghan military and with a host of other government agencies, such as the education and agriculture ministries.

Fratricide has been a growing problem between Afghan soldiers and their foreign counterparts here. In the past, Western military advisers were told to operate cautiously after such incidents, but Allen’s decision represents the first time a commander has publicly withdrawn personnel from their posts for fear of attacks by men in Afghan uniforms.

The Taliban promptly asserted responsibility for Saturday’s attack, saying the shooter was an insurgent who had infiltrated the Afghan security forces.

Western military advisers were warned of a heightened risk of fratricide this week and told to stay out of Afghan ministries unless their activities were “mission critical.”

Although Allen’s announcement will have the most direct impact on those managing Afghan military policy from Kabul, the relationship between Afghan and American soldiers who live and fight alongside one another far from the capital has also turned icy this week. On shared bases in eastern Afghanistan, U.S. military commanders ordered their soldiers to keep their distance from the Afghan counterparts until tension dissipated.

“The mission requires us to spend time with our Afghan counterparts, and lately we haven’t been able to do that,” said one military official in the east who spoke on the condition of anonymity.

NATO forces will continue to withdraw troops from Afghanistan through 2014, and the United States is expected to rely increasingly on small teams of advisers who will assist Afghan soldiers as they assume control of the country’s most volatile provinces. But if the military partnership continues to sour, some wonder whether those advisers will be able to operate safely and effectively without the support of a vast Western security apparatus.

Violent protests began outside Bagram air base early Tuesday after the incineration of Muslim holy books was discovered by Afghan employees. Those demonstrations have rattled the already fragile alliance between NATO forces and the people and government of Afghanistan. Afghan lawmakers have asked that the culprits be tried in an Islamic court.

Allen said in a statement that the investigation into the Koran burning is ongoing. “Working together with the Afghan leadership is the only way for us to correct this major error and ensure that it never happens again,” he said.

He has apologized profusely for the incident, which some officials said involved Korans confiscated from a prison near the Bagram base because they were suspected of being used to pass inflammatory messages.

In addition to Allen’s statements and Obama’s apology to Afghan President Hamid Karzai, the U.S. military has pledged new training to avoid similar mistakes. But the outreach has done little to quell the anger surging through Afghanistan and other parts of the world over an act that Muslims consider a desecration.

U.S. officials say they are disappointed that Karzai has not more vehemently demanded an end to anti-American protests and accepted the U.S. apologies. Karzai issued a statement urging Afghans “not to resort to violence” earlier in the week, but he has since struggled to balance domestic calls for retribution with American calls for reconciliation, declining to publicly offer Americans the kind of absolution that some officials think might put an end to the violence.

Afghan Defense Minister Abdul Rahim Wardak called Defense Secretary Leon Panetta on Saturday to apologize for the killings of the two U.S. military officials and offer his condolences, Pentagon press secretary George Little said. Wardak added that Karzai was assembling a group of religious leaders, lawmakers and other officials to take urgent steps to protect NATO forces and curtail violence in the country.

Wardak and Interior Minister Bismillah Khan Mohammadi are scheduled to visit Washington on Thursday to meet with Panetta and other Pentagon officials.

For his part, Karzai seems keen on using the Koran-burning incident to press his case that Afghans should take responsibility for the U.S. detention facility at Bagram.

“The sooner you do the transfer of the prison, the less you will have problems and unfortunate incidents,” Karzai said at a meeting with Deputy Defense Secretary Ashton B. Carter on Wednesday.

At least three people were killed and dozens wounded Saturday when protests turned violent in Kunduz, a province in northern Afghanistan. One crowd tried to storm the U.N. compound there but was turned back by armed guards.

“Although caused by legitimate defense, the United Nations . . . regrets the casualties among the demonstrators and expresses condolences to the families of those who lost their lives,” the U.N. Assistance Mission said in a written statement.

Staff writers Rajiv Chandrasekaran, Greg Jaffe, Craig Whitlock and Scott Wilson in Washington contributed to this report.