The two Democrats 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.

Image Annise Parker, the city controller, arriving at her election night party. Credit... Smiley N. Pool/Houston Chronicle, via Associated Press

Some national gay-rights groups, meanwhile, came to the aid of Ms. Parker’s campaign with money and volunteers to staff 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.