Two Americans, a service member and a civilian, were shot and killed Wednesday by an Afghan wearing a military uniform at a base near Kabul, according to the U.S. and Afghan officials.
Three other Americans, a service member and two civilians, were wounded, officials said. They were reported hospitalized in stable condition.
It wasn't immediately clear if the so-called "insider attack" involved a Taliban sympathizer, a personal dispute or a cultural misunderstanding.
The shooting comes as the Afghan government in Kabul has come under growing pressure from the Taliban and other armed insurgents despite 15 years of war.
The Pentagon has 9,800 troops deployed in Afghanistan to train and advise Afghan forces, and most rarely participate in direct combat.
But as the war has intensified in recent weeks, U.S. special operations forces have fought alongside Afghan units against Taliban militants in Kunduz and Lashkar Gah.
U.S. and Afghan officials said the gunman opened fire on the five Americans as they attempted to inspect an Afghan ammunition supply base near Camp Morehead, where Afghan military units are trained for specialized operations
The Afghan Ministry of Defense said the gunmen, who was killed as well, was wearing an Afghan army uniform.
"Ministry of Defense has formed a delegation to investigate the incident," said Gen. Dawlat Waziri, spokesman for the defense ministry.
A NATO statement said the Americans were visiting the facility as part of the coalition's efforts to train and advise Afghan security services. An investigation was underway into the incident, the NATO statement added.
The attack marks the eighth U.S. service member killed this year in Afghanistan, according to icasualties.org, a website that tracks the deaths based on public records.
Gen. John W. Nicholson, the U.S. commander in Afghanistan, extended his sympathies to the families of the victims and their military units.
"Anytime we lose a member of our team, it is deeply painful," he said in a statement.
The Pentagon withheld the names of the Americans killed and wounded pending notification of next of kin.
Since 2008, Afghanistan has seen 92 insider attacks, with at least 150 foreign soldiers killed and 187 wounded, according to the Long War Journal blog.
The attacks have bred intense mistrust between Afghan and NATO forces, including U.S. troops, even as the rate of such incidents has dropped in recent years.
More than 2,200 U.S. military personnel have died in Afghanistan since 2001.
Times special correspondent Sultan Faizy contributed from Kabul.
11:25 a.m.: This article has been updated with staff reporting throughout.