The gunman was injured in the incident outside the CURE International hospital and detained by police, officials said, adding that the motive behind the shooting was not immediately known.
"The attacker was a member of the police in the district," Seddiq Sediqqi, spokesman for the interior ministry, told AFP.
"He opened fire as the foreign nationals were entering the hospital, tragically killing three and injuring one more. Another policeman in the area shot the attacker, injuring him."
"With great sadness we confirm that three Americans were killed in the attack on CURE Hospital," the US embassy said on its Twitter account. "No other information will be released at this time."
More From This Section
Kabul has been hit by a spate of attacks targeting foreign civilians this year, including a Lebanese restaurant where 21 people died, an attack on a luxury hotel and the daylight shooting of a Swedish radio journalist.
Last month Taliban militants attacked a Kabul guesthouse used by Roots of Peace, a US anti-landmine charity, killing two people including a girl.
That killing came on the eve of presidential elections to choose a successor to Hamid Karzai as US-led combat troops withdraw from Afghanistan after 13 years of fighting Taliban insurgents.
Cure International is a non-profit organisation founded in 1998, based in Pennsylvania and working in 29 countries including conservative Muslim Afghanistan.
Cure International took over the hospital in west Kabul in 2005 at the invitation of the Afghan government, and runs obstetrics, gynaecology, pathology and surgery departments as well as training schemes for doctors and nurses.