(CNN) -- Gay rights advocates in South Africa hailed a judge's sentencing of four men to 18 years each in prison for brutally slaying a 19-year-old lesbian.
Hatred fueled the 2006 stabbing and stoning of Zoliswa Nkonyana, who was targeted because of her sexual orientation, Magistrate Raadiya Whaten ruled.
Four years' credit was given to Lubabolo Ntlabathi, Sicelo Mase, Luyanda Londzi and Mbulelo Damba, meaning they will spend 14 additional years behind bars.
"The sentence sent a strong message that hate crimes would not be tolerated," national prosecuting attorney spokesman Eric Ntabazalila told the South African Press Association.
Gay rights advocates celebrated Wednesday's ruling.
"It was the first time discrimination based on sexual orientation was named as an aggravating factor in a South African criminal trial," the Triangle Project gay and lesbian rights group said in a written statement.
Gay marriage is legal in South Africa, which was the first African nation to prohibit discrimination based on sexual orientation.
Homosexuality is illegal in most African countries, based on rules left over from the British colonial era, when sodomy laws were introduced.
Despite South Africa's anti-discrimination provisions, attacks based on sexual orientation persist, rights groups say.
After interviews in six of South Africa's nine provinces last year, New York-based Human Rights Watch concluded that "social attitudes towards homosexual, bisexual, and transgender people in South Africa have possibly hardened over the last two decades. The abuse they face on an everyday basis may be verbal, physical, or sexual -- and may even result in murder"
This week officials from another rights group said they hope this week's sentencing will set a precedent across Africa.
"We hope that this message is heard loud and clear across the rest of the continent, where homophobic discrimination is widespread and where homosexuality is a crime," the non-profit People Against Suffering, Oppression and Poverty said in a statement.
CNN's Aliza Kassim contributed to this report.