The motive was not immediately clear, but no U.S. embassy personnel were involved in the incident.
National police spokesman George Kinoti said an investigation had begun and said the man was killed by the police officer in self defense.
“It was a lone criminal who attacked a police officer,” Kinoti told Reuters. “He was armed with a knife”
A U.S. Embassy spokeswoman confirmed there had been a “shooting incident” outside the mission, which is located in a heavily secured compound in the north of the capital.
“No embassy personnel were involved,” U.S. Embassy spokeswoman Fiona Evans said, without giving further details.
Kenyan media said the police officer had been guarding one of the entrances to the embassy compound when he was assaulted.