Swiss voters agreed on Sunday to penalize public homophobia, greenlighting an amendment to an antidiscrimination law that had not provided protection for lesbians, gay men and bisexual people.

The amendment, which was years in the making, was challenged by opponents arguing that it would stifle freedom of expression.

Voters were asked in a referendum whether they wanted to extend Switzerland’s racism statutes to sexual orientation, and on Sunday 63.1 percent voted in favor of it. The extension was backed by the government and most of Switzerland’s political parties.

Unlike most countries in Western Europe, Switzerland did not have a law that specifically protects lesbians, gay men and bisexual people from discrimination. Publicly denigrating someone’s sexual orientation, or inciting hatred against someone in public, could not be prosecuted.