Many demonstrators chanted "Kill the Gays!" and "Allahu Akbar!"
At least eight people have been injured in clashes during the opening ceremony of Bosnia's first gay festival in the capital Sarajevo, police have said.
They said dozens of men attacked participants of the festival in front of the city's Academy of Fine Arts.
A foreigner and journalists were reportedly among the injured.
Homosexuality is very much a taboo issue in Bosnia and organisers of the Queer Festival have received death threats, correspondents say.
Anti-gay protesters attacked the festival participants as they were leaving the opening ceremony in central Sarajevo on Wednesday evening.
Many demonstrators chanted "Kill the Gays!" and "Allahu Akbar!" (God is Great).
"When I was getting out of the academy, I was suddenly struck in the back. Three other people then came running and beat me up," festival participant Pedja Kojovic told the AFP news agency.
Violence spread to nearby streets, before police managed to disperse the protesters.
Holding a gay festival in Bosnia has been condemned by some politicians and sections of the media, the BBC's Helen Fawkes in Sarajevo says.
Sarajevo is a predominantly Muslim city, and religious leaders have said that the timing of the four-day event - coinciding with the Muslim holy month of Ramadan - is provocative, our correspondent says.
Amnesty International and a number of other human rights groups have expressed concern at the level of homophobia and the attempts to incite violence in the run-up to the festival.
The organisers said they did not set out to offend anyone, and that the aim was to use art and culture to raise awareness.
But now it has become a political event, and the organisers are more determined than ever that the gay festival should take place over the next few days, our correspondent says.