Annise Parker, the city controller, arriving at her election night party.
Cheers and dancing erupted at Ms. Parker’s campaign party as her opponent, Gene Locke, a former city attorney, conceded defeat just after 10 p.m. when it became clear he could not overcome her lead.
Twenty minutes later, Ms. Parker appeared before ecstatic supporters at the city’s convention center and then joked that she was the first graduate of Rice University to be elected mayor. (She is, by the way.) Then she grew serious.
“Tonight the voters of Houston have opened the door to history,” she said, standing by her partner of 19 years, Kathy Hubbard, and their three adopted children. “I acknowledge that. I embrace that. I know what this win means to many of us who never thought we could achieve high office.”
With all precincts reporting, Ms. Parker, the city controller, had defeated Mr. Locke 53 percent to 47 percent.
Throughout the campaign, Ms. Parker tried to avoid making an issue of her sexual orientation and emphasized her experience in overseeing the city’s finances. But she began her career as an advocate for gay rights in the 1980s, and it was lost on no one in Houston, a city of 2.2 million people, that her election marked a milestone for gay men and lesbians around the country.
Several smaller cities in other regions have chosen openly gay mayors, among them Providence, R.I., Portland, Ore., and Cambridge, Mass. But Ms. Parker’s success came in a conservative state where voters have outlawed gay marriage and a city where a referendum on granting benefits to same-sex partners of city employees was soundly defeated.
Turnout was light across the city on a rainy, foggy day, with only about 16 percent of registered voters going to the polls.
Ms. Parker’s sexual orientation did not become an issue in the race until after the general election produced no winner and led to a run-off between her and Mr. Locke, who is black and enjoys strong support among African-American voters.
The two candidates differed very little on the issues. Mr. Locke, who is 61, promised to crack down on crime and expand the police department. Ms. Parker, 53, said her experience as controller made her a better candidate to steer the city through the tough financial times it now faces.
The candidates also started slinging stones at one another in final weeks as it became clear neither had a huge advantage in the few polls conducted here. Mr. Locke bashed Ms. Parker as “soft on crime” and suggested she favors tax increases. She portrayed him as nothing more than a lobbyist for developers.
But the ugliest attacks came from a group of black pastors who spoke out against Ms. Parker for what they called her gay agenda and two separate anti-gay advocates who sent out fliers in the mail calling attention to her support from gay groups and to her relationship with her partner. Mr. Locke denied having anything to do with the attacks, but two members of his finance committee gave $40,000 to help finance one of the mailings.
Some national gay-rights groups, meanwhile, came to the aid of Ms. Parker’s campaign with money and volunteers to man telephone banks in a get-out-the-vote effort and to urge her likely supporters to vote.
Political strategists said that to win, Mr. Locke needed to carry a large majority of the black vote, which is usually around a third of the turnout, and to attract significant support from conservative whites, many of them Republicans, who are also about a third of the voting mix here.
The crowd at Ms. Parker’s speech included dozens of young gay men and lesbians who had volunteered on her campaign. Many were elated with the sense of history being made.
“It’s a huge step forward for Houston,” said one of the volunteers, Lindsey Dionne, who is lesbian. “It shows hate will not prevail in this city.”
Robert Shipman, who is gay and worked long hours for Ms. Parker, said: “The diversity in this room, it’s not just gay people, it’s gay, straight, black, white, Jew, Christian, Muslim, every kind of person. It took all of us to get to this point.”
For his part, Mr. Locke was gracious in defeat, calling for unity after what had sometimes been a heated campaign. “We have to all work together to bring our city closer and closer together,” he said.
Ms. Parker appeared to have cobbled together a winning coalition of white liberals and gay people, who were expected to turn out in large numbers.
Rachel Marcus contributed reporting from Houston.