Updated

A controversial Houston proposal barring discrimination against gay and transgender people that stirred a national debate over the balance between gay rights and religious freedom was soundly defeated in a referendum Tuesday.

The Houston Equal Rights Ordinance was rejected by close to a 2-to-1 margin. The vote followed a nearly 18-month battle that spawned rallies, legal fights and accusations on both sides.

Supporters of the ordinance said it would have offered increased protections for gay and transgender people, as well as protections against discrimination based on sex, race, age, religion and other categories.

Opponents, including a coalition of conservative pastors, said it infringed on their religious beliefs.

In the months leading up to Tuesday's vote, opponents focused their campaign on highlighting one part of the ordinance related to the use of public bathrooms by transgender men and women that opponents alleged would open the door for sexual predators to go into women's restrooms.

Democratic Houston Mayor Annise Parker, who is gay, and other supporters of the ordinance had called this "bathroom ordinance" strategy misleading.

The ordinance was initially approved by the Houston City Council in May 2014 but a lawsuit to have residents vote on the measure eventually made it to the Texas Supreme Court, which in July ordered the city to either repeal the ordinance or put it on the ballot.

Tuesday's referendum drew attention from around the nation, with the measure getting high-profile endorsements last week from the White House, high-tech giant Apple and Democratic presidential candidate Hillary Clinton. The ordinance also had received support from other members of Houston's religious community.

Campaign for Houston, which fought the ordinance, said opponents included a diverse group of individuals, such as pastors from all denominations and local and state elected officials.

On Monday, Republican Texas Gov. Greg Abbott had tweeted his support for opponents, saying, "HOUSTON: Vote Texas values, not @HillaryClinton values. Vote NO on City of Houston Proposition 1. No men in women's bathrooms."

The Associated Press contributed to this report.