Eight US troops and a US contractor have been killed by an Afghan air force pilot at Kabul airport in an apparent argument, US officials say.
The incident took place at a facility used by the Afghan air force at about 1100 local time (0630 GMT), the Afghan defence ministry said.
The pilot was also killed in the exchange.
The incident is the deadliest of a number of recent attacks on foreigners by Afghan security personnel.
"We can confirm there was small-arms fire during this incident," said Nato-led International Security Assistance Force (Isaf) spokesman Maj Tim James.
US officials said the eight Isaf troops and one foreign contractor were all American, AP news agency said.
Witnesses reported hearing sirens and seeing a heavy military presence near the facility, which generally has tight security.
A senior Afghan security official told the BBC the pilot's name was Gul Ahmad, and he came from the Tarakhel area of Kabul.
He was suffering from "mental illness", and either got into a fight with his foreign colleagues or planned the attack after being recruited by the Taliban, the official said.
A spokesman for the Afghan Air Corps, Col Bahader, told AP the shooting was in an operations room of the Afghan Air Corps.
"Suddenly, in the middle of the meeting, shooting started," Col Bahader said. "After the shooting started, we saw a number of Afghan army officers and soldiers running out of the building. Some were even throwing themselves out of the windows to get away."
The Taliban claimed responsibility for the incident in a text sent to AP but the authorities have not confirmed any insurgent activity.
President Hamid Karzai and senior Isaf commanders condemned the shooting.
The head of the Nato training mission in Afghanistan, Lieutenant General William Caldwell said the programme had "suffered a tragic loss from an attack, which occurred this morning, resulting in the deaths of nine coalition trainers".
Correspondents say rapid recruitment into the Afghan military has raised fears of Taliban infiltration into the police and army.
Nato's exit strategy for Afghanistan involves progressively handing over to the local security forces.
Until now the deadliest of the recent attacks on foreign troops was last November when an Afghan policeman killed six US soldiers.
And two Nato soldiers were shot dead by an Afghan border policeman in northern Faryab province on 4 April, local officials said.
The BBC's Quentin Sommerville in Kabul says foreign troops broadly but not totally trust their Afghan colleagues and feel they have to keep half an eye on them.
The attackers are sometimes actually members of the Afghan security forces, and sometimes insurgents impersonating servicemen.