A Ugandan High Court judge has ruled that media companies in the country should not publish the identities of people they say are homosexuals.
The decision was described as a "landmark ruling" by gay rights activists.
The case was brought against The Rolling Stone newspaper which last year published several lists of people its editor said were gay.
Many said they were attacked after their names and photos were printed.
Homosexual acts are illegal in Uganda and activists say the gay community still lives in fear.
"The judge granted a permanent injunction against Rolling Stone from publishing these names," lawyer John Francis Onyango, who represented the three gay rights campaigners who brought the case, told AFP.
"But the ruling went beyond these applicants and extended to all media," he added.
The newspaper argued that as the three people who brought the case were known gay rights leaders, it could not be punished for saying they were homosexuals.
But Judge Vincent Musoke-Kibuuke ruled that their lives had been threatened as they risked being attacked by vigilantes, Mr Onyango said.
One of the articles published had the headline "Hang them" above a list of names and photos.
The three were also awarded 1.5m Ugandan shillings ($650; £430; 500 euros) in compensation and the newspaper was ordered to pay all associated legal costs.
One of the petitioners, Pepe Julian Onziema, told the BBC's Focus on Africa programme that she welcomed the ruling.
"It sets precedent in this country, and across Africa," she said.
"A lot of the danger that we have been facing has been the result of the local media here. It's basically set a standard for the media to begin treating us as humans, as part of the community."
Ms Onziema said compensation was "not an important factor for us", and that it had been more a question of protecting lives.
"We'd had enough because we were in lots of danger already. Then Rolling Stone went a notch higher by calling for the hanging of gay people," she added. "We had to put a stop to it."
A coalition grouping together human rights campaigners said they were pleased the High Court had taken this "principled step".
"This ruling is a landmark not only for sexual and other minorities living in Uganda, but also an important precedent for other countries facing similar issues," the Civil Society Coalition on Human Rights and Constitutional Law in Uganda said in a statement.
Last year, a local MP called for the death penalty for some homosexual acts. The proposed Anti-Homosexuality Bill sparked an international outcry and a year later has not been formally debated by parliament.