“An issue that otherwise would primarily be confined to local media coverage and some protests by social conservatives has taken on a state and even national level scope, and that’s due to the fact that Julián Castro is involved,” said Mark P. Jones, a political science professor at Rice University in Houston.

Republican officials and others seeking to defeat the ordinance said their opposition had nothing to do with politics. They described it as a thinly veiled attack on those who hold traditional rather than liberal values.

Mr. Abbott, the attorney general, sent a letter to Mr. Castro stating that passage of the ordinance would most likely “envelope the city in costly litigation,” though he stopped short of suggesting the state would challenge it in court. Mr. Abbott wrote that the measure conflicts with the Constitution, because it threatens to remove from office any city official who shows a bias “by word or deed” based on sexual orientation.

“The obvious problem with this provision is that it allows government to impose thought and speech control over any city official or board or commission member who may hold deep religious beliefs that are counter to the ordinance,” Mr. Abbott wrote.

The ordinance adds sexual orientation and gender identity to the list of classes protected from bias, including race, religion, age and disability. It affects city employees, city contracts, housing and city officials as well as members of municipal boards and commissions. It also applies to restaurants and other businesses, making it unlawful to deny anyone any services available to the general public on the basis of sexual orientation or any of the other protected classes. Language was added that no person or group was required to support or advocate “any particular lifestyle or religious view.”

The tone of the debate has been sharp. Supporters and opponents held dueling news conferences on the front and back steps of City Hall. Hundreds flooded the Council chambers to speak for or against the measure, with supporters dressed in red shirts and opponents in blue.

Councilwoman Elisa Chan, who voted against it, angered supporters when secretly recorded comments she made to staff members about gays and lesbians became public in The San Antonio Express-News. She called homosexuality “disgusting” and said gays should not be allowed to adopt. She has since defended her remarks.

Mr. Castro said the passage of the ordinance by the 11-member Council proved that San Antonio belongs to everyone, regardless of the stance of Republican leaders. “It’s not surprising during campaign season that politicians from outside the city would chime in on an issue like this,” he said. “I respect their perspective, but we did what’s in the best interest of San Antonio.”