The Taliban claimed responsibility for the attack, saying it was retaliation for the Quran burnings, and the NATO commander recalled all international military personnel working in Afghan ministries in the capital.
The two advisers were shot in the back of the head, according to two Western officials, who spoke on condition of anonymity because they were not authorized to disclose the information.
U.S. officials said the assailant remained at large and a manhunt was under way.
An apology from President Barack Obama has failed to quell public outrage over what NATO insisted was an accidental desecration of the Quran. At least 28 people have been killed and hundreds wounded since Tuesday, when it first emerged that Qurans and other religious materials had been thrown into a fire pit used to burn garbage at Bagram Air Field, a large U.S. base north of Kabul.
Among those dead were two U.S. soldiers who were killed Thursday by one of their Afghan counterparts while a riot raged outside their base in the eastern province of Nangarhar.
Gen. John Allen, the commander of NATO and U.S. forces in Afghanistan, said he recalled all NATO personnel from the ministries "for obvious force protection reasons" but the alliance remains committed to its partnership with the Afghan government.
He said NATO is investigating Saturday's shooting and will pursue all leads to find the person responsible for the attack.
"The perpetrator of this attack is a coward whose actions will not go unanswered," Allen said.
NATO forces have advisers embedded in many Afghan ministries, both as trainers and to help manage the transition to Afghan control and foreign forces prepare to withdraw by the end of 2014. The Afghan Interior Ministry oversees all of the country's police, so has numerous NATO advisers.
Two Afghan officials said the ministry shooting did not involve any Afghans. They spoke on condition of anonymity because they were discussing a NATO incident. One of the officials noted that the shooting occurred inside a secure room at the ministry that Afghan staff do not have access to.
NATO confirmed that two service members were killed, but spokesman Lt. Col Jimmie Cummings said "initial reports say it was not a Western shooter." He declined to provide further information.
A U.S. official in Washington confirmed that the two killed were Americans. The official spoke anonymously because the information has not been publicly released.
Tensions between the Afghans and the Americans already were high following the Quran burnings. Anti-American sentiment has been on the rise in the war-weary country, and several foreign troops have been killed by Afghan soldiers in recent months. Some of those shootings have been blamed on personal hostilities, while others have been attributed to Taliban infiltrators.
In a statement, Taliban spokesman Zabiullah Mujahid said the gunman was an insurgent named Abdul Rahman. He said an accomplice inside the ministry helped him get inside the compound. He said the killings were a planned response to the Quran burnings.
"After the attack, Rahman informed us by telephone that he was able to kill four high-ranking American advisers," Mujahid said. The Taliban frequently exaggerate casualty claims.
In Kunduz, the capital of Kunduz province in northeast Afghanistan, more than 1,000 protesters demonstrated against the Quran burnings. At first they were peaceful, but as the protest continued they began throwing stones at government buildings and a U.N. office, said Sarwer Hussaini, a spokesman for the provincial police. He said the police were firing into the air to try to disperse the crowd.
Dr. Saad Mukhtar, health department director in Kunduz, said at least three protesters died and 50 others were injured during the melee.
The U.N. confirmed in a statement that its Kunduz compound was attacked, but said all its staff in Kunduz and in the rest of the country were unhurt and safe.
Associated Press writers Patrick Quinn in Kabul and Robert Burns in Washington contributed to this report.