Houston would seem, at first glance, an unlikely site for the gay-rights movement’s first major setback since the Supreme Court legalized same-sex marriage nationwide.

The nation’s fourth-largest city has elected a lesbian mayor three consecutive times without much controversy, and in 2014, its city council approved an ordinance protecting residents from discrimination based on sexual orientation, gender identity, and 13 other factors. But when that same proposal came before the electorate on Tuesday, it lost out to an opposition campaign armed with a startlingly simple message: “No men in women’s bathrooms.” Opponents led 61 to 39, with 66 percent of the precincts reporting on Tuesday night.

After a hard-fought campaign that drew national attention from Hollywood celebrities and presidential candidates, voters rejected the Houston Equal Rights Ordinance, or Proposition 1, handing a victory to conservative critics who argued that its expansive protections for transgender people could endanger women and children.

Championed by the city’s outgoing mayor, Annise Parker, the ordinance represented an early test of the gay-rights movement’s effort to guarantee that Americans who just secured the right to marry would not face discrimination in employment, housing, or public accommodations. Many of the classes listed in the ordinance—race, sex, age, and religion, among others—are already protected under federal law, but sexual orientation and gender identity are not.

Proposition 1 was only on the ballot this year because the Texas Supreme Court in July struck down the ordinance passed by the city council, ruling that the question of anti-discrimination protections must be put before the voters. For supporters, the fall campaign featured a straightforward message about equality and inclusiveness. For opponents, it became all about bathrooms.

Seizing on the proposal’s gender-identity provision, a group calling itself the Campaign for Houston recruited women, pastors, and even the ex-Astros star Lance Berkman to warn that the ordinance would allow predatory men legal cover to enter women’s bathrooms simply by claiming they identify as female. “No one is exempt,” intoned a narrator in one TV ad that featured a young girl in a restroom. “Even registered sex offenders could follow women or young girls into the bathroom. And if a business tried to stop them, they’d be fined. Protect women’s privacy. Prevent danger. Vote no on the Proposition 1 bathroom ordinance.”

The campaign was as explicitly based on fear as any in modern memory. While the group included testimonials from women who said they were followed into bathrooms by men or harassed, they offered no evidence that similar anti-discrimination ordinances on the books in dozens of other cities had led to an uptick in bathroom incidents or violence. And yet, even supporters of the ordinance acknowledged it was effective in playing to the anxieties of voters who may have little familiarity with transgender people. “We’ve known that it takes some time to address that anxiety, address it head on, and also to make sure that voters take a step back and look at what the ordinance actually is and how it would function,” said Richard Carlbom, campaign manager for Houston Unites, a group supporting approval of the law.

Supporters pointed out that it was already against the law in Houston to enter a bathroom with the intent to harass someone. And they branded the equal-rights ordinance with a seemingly unassailable acronym: HERO. But whether their argument was valid or not, opponents had already prevailed in one key political test—having the simpler, easier-to-understand message. “They’ve just run a very disciplined and very effective campaign,” said Mark Jones, a political scientist and a fellow at Rice University’s Baker Institute.

In the waning days of the campaign, Hillary Clinton and Bernie Sanders weighed in with endorsements of the ordinance, while Texas's conservative governor, Greg Abbott, went after Clinton and embraced the opposition’s “no men in women’s bathrooms” slogan at the same time.

Both sides expected the election to be close, but in the hours before the vote was counted, Carlbom seemed prepared for a narrow defeat. “What you see in Houston is a reaction to a national climate where Americans now have a freedom to marry,” he told me. “And that fight to secure the freedom to marry took a significant amount of public education, and I think that’s where we’re today.”

Perhaps it was the big-picture confidence gleaned from the movement’s much larger victory this summer at the Supreme Court, but Carlbom didn’t appear particularly worried about the prospect of losing. “They have a message that can be impactful in the short term,” he said of the opponents, before resorting to a time-tested adage of the defeated. “But in the long term, the arc of the moral universe bends toward justice, and it’s only a matter of time before all Houstonians and all Americans enjoy those protections.”

Carlbom’s attitude might partly be due to the belief that even with a loss on Tuesday, a narrower anti-discrimination ordinance is likely to pass when a new mayor takes office next year. Opponents of Proposition 1 have said they would support a proposal that includes exemptions for bathrooms and locker rooms. “I would expect that type of ordinance to pass very quickly, with if not unanimous support then near-unanimous support in the city council,” Jones said.

With her term almost over, Parker refused to back off a fully-inclusive measure, but her successor might be more open to compromise. “She went for the maximum. She didn’t go for the 90 percent,” Jones said. “I think it reflects that HERO pushed just beyond the comfort zone of many Houstonians. And that small area beyond their comfort zone has been magnified 100-fold by the ‘no’ campaign.”