He then fled and blew himself up in his house when police surrounded the area.
Prime Minister Denis Zvizdic later said at an emergency meeting of his cabinet it was an attack "on the state".
But he refused to be drawn on whether the man, named as Enes Omeragic, was a jihadist militant.
However other officials have told local media that the attacker was linked to a radical Islamist movement.
Boris Grubesic, a spokesman for the state prosecution, told the Associated Press news agency that the attack was being investigated as "an act of terrorism".
In April, a gunman attacked a police station in the eastern town of Zvornik, killing an officer and injuring two others before being shot dead.
Police said the gunman was shouting "Allahu Akbar!" ("God is great!") during the assault.
More about: