The man injured at least one police officer guarding the embassy before police surrounded him. After a 30-minute standoff, the sound of a single shot echoed and the shooter slumped to the ground.
Police arrested the wounded man and took him away in an ambulance as pedestrians watched from behind buildings and vehicles. Sarajevo police spokesman Irfan Nefic said the man was being treated at a hospital.
The U.S. Embassy said none of its employees was injured.
Bakir Izetbegovic, one of Bosnia's three presidents, issued a statement condemning "the terrorist attack on the embassy of the United States in Bosnia-Herzegovina."
"The United States is a proven friend of Bosnia-Herzegovina. Its government and its people supported us in the most difficult moments in our history and nobody has the right to jeopardize our relations," he said.
The gunman wore a beard and was dressed in an outfit typical for followers of the conservative Wahabi branch of Islam.
Bosnian TV identified the shooter as Mevlid Jasarevic, from Novi Pazar, Serbia. It said he is a Wahabi follower, but did not cite its sources.
The Wahabis are an extremely conservative branch of Islam which is rooted in Saudi Arabia and linked to religious militants in parts of Afghanistan and Pakistan.
A Sarajevo city official, Muhamed Budimlic, told The Associated Press that a policeman guarding the embassy was injured.