Two Nato officers have been killed in the interior ministry in the Afghan capital Kabul, coalition officials say.
Nato said an "individual" had turned his gun on the officers but denied earlier reports he was a Westerner.
Afghan security officials said those killed were an American colonel and major. Local media reports suggest the incident followed a "verbal clash".
Nato commander Gen John Allen said all Nato personnel were being recalled from Afghan ministries on security grounds.
A UK embassy spokesperson had earlier said all British civilians were being withdrawn from the ministries in what was hoped would be a temporary measure.
The shootings come amid five days of deadly protests over the burning of copies of the Koran by US soldiers.
The interior ministry was put in lock-down after the shootings, officials said.
The BBC's Orla Guerin in Kabul says eight shots were reported inside the building, which should be one of the safest in the capital, and that any Afghan who carried out the attack would have had the highest clearance.
Local media reports said the gunman was an Afghan policeman but this has not been confirmed.
Gen Allen said he condemned the attack, adding: "We will pursue all leads to find the person responsible. The perpetrator of this attack is a coward whose actions will not go unanswered."
He added: "For obvious force protection reasons, I have also taken immediate measures to recall all other Isaf personnel working in ministries in and around Kabul."
Isaf spokesman Brig Gen Carsten Jacobson told the BBC that Nato could not yet confirm the identity of those killed.
He would also not be drawn on any link to the Koran protests.
Gen Jacobson said: "We have seen an emotional week, we have seen a busy week - but it would be too early to say this incident was linked to what we have seen over the last days.
"At the moment, it is too early to say what actually happened."
Early reports suggest the two officers were shot in the ministry's command and control centre.
The BBC's Bilal Sarwary in Kabul says this is where representatives of 34 provinces meet to plan security.
He quotes sources as saying that Interior Minister Bismullah Khan was having a meeting with senior Western officials elsewhere in the building when the shooting took place.
The Taliban said in a website statement that it carried out the attack in response to the Koran burnings.
Angry protests over the burning of the Korans continued on Saturday, with a UN compound in the city of Kunduz set alight.
Four people were killed and dozens injured in clashes in the city, according to local doctors. Three more people were killed in the southern province of Logar.
The governor's house in Laghman province also came under attack on Saturday and there were demonstrations in Paktia, Nangarhar and Sari Pul provinces.
More than 20 have died since the protests began on Tuesday.
On Friday Nato's Afghanistan commander Gen John Allen had appealed for calm.
US personnel apparently inadvertently put the books into a rubbish incinerator at Bagram air base, near Kabul.
US President Barack Obama has apologised for the Koran-burning incident.
In a letter to his Afghan counterpart Hamid Karzai, Mr Obama said the books had been "unintentionally mishandled".
Muslims consider the Koran the literal word of God and treat each book with deep reverence.