"The officer fired back in self-defense and managed to kill (the attacker). My officer is in hospital in a stable condition. The victim died on the spot," Vitalis Otieno, the Gigiri division commanding officer of the Nairobi Police, told CNN.
The man killed was a Kenyan national, police said, but they are not releasing his name while the case is under investigation. His motive was not immediately clear.
The officer was stabbed in the head, Otieno said. Further details about the officer's injury weren't immediately available.
The US Embassy confirmed that a shooting had taken place outside its premises and said none of its staff members were involved.
Photos circulating on social media showed what appeared to be the man, lying lifeless next to a pool of blood as a uniformed officer looks over him, taking notes.
The US Embassy is located in Nairobi's Gigiri district among several other embassies and United Nations offices.