A police spokesman told Bosnian TV that police wounded and arrested the man, who was then taken to a hospital.
Photographs from the scene showed a bearded man walking down the street carrying an assault rifle.
A spokeswoman for the US embassy said there had been "an incident" near the embassy, which was in lockdown.
After the shots were fired, police sealed off the area. Bystanders watched from behind vehicles and buildings.
"The person who fired an automatic weapon was wounded and arrested during the police operation," police spokesman Irfan Nefic told BHT television.
"After receiving medical treatment on the scene the person was hospitalised."
Bosnian media have reported the gunman was a member of the Islamic fundamentalist Wahhabi sect.