The shooting at Cure International Hospital, western Kabul, was the latest in a string of deadly attacks on foreign civilians in the Afghan capital this year.
Minister of health Soraya Dalil said the third American victim was a Cure International doctor who had worked in Kabul for seven years.
The attacker was a member of the Afghan Public Protection Force assigned to guard the hospital, according to District Police Chief Hafiz Khan. He said the man's motive was not yet clear.
The gunman, who was detained, was wounded during the attack and underwent surgery in the same medical facility under heavy police guard according to Kanishka Bektash Torkystani, a health ministry spokesman.
Mr Torkystani said: "Five doctors had entered the compound of the hospital and were walking toward the building when the guard opened fire on them."
The Afghan capital has seen a spate of attacks on foreign civilians this year, a worrying new trend as the US-led military coalition prepares to withdraw most troops by the end of the year.
It was unclear whether the Taliban were behind the latest shooting, although the insurgents have claimed several major attacks that killed foreign civilians this year.
The shooting was the second "insider attack" by a member of Afghan security forces targeting foreign civilians this month.
On April 4, an Afghan police officer shot two Associated Press staff working in the eastern province of Khost, killing photographer Anja Niedringhaus and wounding veteran correspondent Kathy Gannon.
Violence and insecurity have been spiralling in Afghanistan amid uncertainties surrounding the April 5 presidential election and the upcoming withdrawal at the end of the year of most international troops.