In 2015, in America’s fourth-largest city and one of its most diverse, backing the Houston Equal Rights Ordinance might have seemed an obvious choice.

The ordinance passed May 2014 to protect against a broad range of discrimination had a noble nickname: Hero. It enjoyed the support of the White House, the likely Democratic presidential nominee, local and national civil rights groups, Hollywood celebrities, regional business groups and major companies including Apple.

The pro-Hero campaign made sensible appeals to voters, raising the potential negative impact on the city’s image and economy of repealing a bill that simply protected against discrimination for 15 broad categories, among them not just sexual orientation and gender identity, but also race, marital status, pregnancy, age, religion and military service.

The campaign had $3m in funds and a strong grassroots effort, from volunteers canvassing and putting up placards to one person starting a Twitter memes account called Houston Cats for Hero.

And then the ballots were counted. With the country watching, Houston voters overwhelmingly decided to reject Hero on Tuesday night, dealing LGBT rights campaigners their first big setback since marriage equality was won nationwide this past summer and underlining that resistance from the religious right remains strong in some parts of the US.

“It’s not surprising to see backlash,” said Jennifer Levi, director of the Gay & Lesbian Advocates & Defenders’ transgender rights project. “It’s hugely disappointing, but it’s part of what happens when you have discussions about marginalised groups. This fight may have sharpened the opposition, but it expanded the range of support for transgender equality.”

The pro-Hero campaign relied on logic and reasonableness, which as a strategy turned out to be no match for a stark yet spurious slogan from opponents: “No men in women’s bathrooms.”

This line, peddled endlessly and rooted in groundless suspicion of transgender people, sought to scare voters into believing that because of the reference to gender identity, a broad civil rights bill was in essence a license for sexual predators to attack women in bathrooms.

Nationwide, transgender rights advocates are scrutinising the loss for lessons to apply to future fights. The outcome exposes a persistent gap between the courts, where trans rights advocates have been increasingly successful in winning protections under existing laws and public opinion.

Mara Keisling, the founder and director of the National Center for Transgender Equality, said one takeaway from the Houston vote is that trans rights suffer in areas of the country where transgender individuals don’t have enough visibility.

“This was, clearly, a lack of underlying, fundamental public awareness and acceptance,” she said. “We know that once people know a trans person personally, or even just know a little bit more about us, it’s harder to bring up these old stereotypes and scare tactics that don’t have any basis in truth. But you can’t just say, ‘that’s not true’ without being known to people and trusted.”

Keisling also criticized local media outlets that gave equal credence to supporters of the measure and those who raised bogus fears about predators. In combatting these stereotypes, she said, trans rights advocates face the same public relations task that once faced the gay rights movement.

“Fears about gay predators becoming teachers held back that movement for a long time,” she said. “It’s a tried-and-true tactic of the right wing. They’re giving people a reason to say, ‘Well, somebody thinks there is a risk of predators in this situation, so reluctantly, I have to go along with them.’ We need to really pay attention to, do people know us?”

The winning side, meanwhile, hope their success will inspire similar revolts in other US cities. “We’re fed up with being threatened and intimidated. It’s time for people across the nation to stand up and say we’re not taking this anymore,” Steve Riggle, a pastor in Houston, told Fox News.

As Hero supporters consoled themselves with brisket and beer at a downtown barbecue joint on Tuesday, anti-ordinance activists celebrated at a post-election party in a swanky hotel eight miles away. The Texas lieutenant governor, Dan Patrick – a Republican who is the state’s second most powerful politician – took to the stage and reiterated the anti-campaign’s core message. “It was about protecting our grandmoms and our mothers and our wives and our sisters and our granddaughters,” he said.

One commercial depicted a man following a schoolgirl into a toilet stall. The fearmongering clearly resonated with voters who strongly spurned what, on the face of it, should have been an unremarkable bill: 61% voted against it and 39% for, though only about 260,000 votes were cast in a city of 2.2 million inhabitants, making for a turnout of 27% among registered voters.

Despite the ordinance explicitly offering protections based on race, colour, national origin and ethnicity, a Houston Chronicle results map shows that some of the strongest resistance came not only from conservative, suburban, mainly white areas but from predominantly black and Hispanic neighbourhoods.

Yet as proponents pointed out, more than 200 cities have similar ordinances on the books, including Texas’s major urban areas. Dallas, similar in size, culture and demographics to Houston, updated its charter without fuss a year ago to clearly include non-discrimination protections for city employees based on sexual orientation, gender identity and expression. More than three-quarters of voters were in favour and the move built on a 20-year-old ordinance.

But there were special circumstances in Houston: a loud band of dissenters with a powerful spin, a sense among Christian conservatives that the traditional family is under attack, especially in the wake of the US supreme court legalising same-sex marriage in June, and a desire to give the mayor a black eye.

Annise Parker, who is leaving her post in January after winning the maximum three terms, is a Democrat who became the first openly gay mayor of a major US city in 2009. She made the ordinance a personal mission, attracting critics who said she was pursuing a “gay agenda” and outraged pastors – and there are a lot of them in this Bible belt metropolis – by trying to subpoena their sermons as part of protracted legal wrangles after the city council passed the ordinance last year.

Despite the reference to religious protection included in the ordinance, some of its opponents portrayed the vote as a battle for religious liberty, evoking memories of clashes over so-called “religious freedom” laws in Indiana and Arkansas last spring and in Arizona last year.

As politicians weighed in, an equality issue also took on a predictably partisan Republicans-versus-Democrats hue. Greg Abbott, the Republican Texas governor, took to Twitter to urge voters to “Vote Texas values, not @HillaryClinton values”.

Patrick said voters told “those who supported this, including Hillary Clinton, who wants to be the next president, that you’re out of touch with America, you’re out of touch with your own party, you’re out of touch with common sense, you’re out of touch with common decency. I’m glad Houston led tonight to end this constant political correctness attack on what we know in our heart and our gut is not right”.

DeAnne Cuellar, a spokeswoman for Equality Texas, a partner in the pro-Hero Houston Unites coalition, said the result is “a huge defeat, especially coming after such a big win with marriage equality”, and said it owed much to opponents successfully framing it as a “bathroom” ordinance. “I don’t think this is reflective of Houston. It’s a warm and welcoming city,” she said.

Cuellar, echoing Parker’s concession speech, said that activists will lick their wounds, analyse what went wrong and then make a renewed push for equal rights in a place where local laws matter because there are no statewide anti-bias protections for LGBT people. “Nobody’s giving up,” she said.