Fernando Ferrer, a former Bronx borough president of Puerto Rican descent, apparently will face Rep. Anthony D. Weiner in a runoff election for the Democratic mayoral nomination.

With nearly all the votes counted, Ferrer was stuck at 39.95 percent, falling just short Tuesday night of gaining the 40 percent needed to avoid a runoff. Weiner had 28.8 percent in the six-way contest.

Mustachioed and streetwise, Ferrer is a social moderate who could appeal to a now-majority Latino and black city, while scooping up sizable numbers of white votes. Weiner, who is Jewish, is an ebullient candidate whose surging campaign focused on middle-class issues of taxes and city services.

Neither Ferrer nor Weiner would face an easy task in November. Mayor Michael R. Bloomberg (R) is a plutocratic media mogul who expects to lavish at least $70 million of his own money on his reelection campaign. Bloomberg has already spent more than any of the Democrats.

Although Democrats outnumber Republicans 5 to 1 in the city, recent polls have shown Bloomberg running ahead of any Democrat. And Ferrer, who has close ties to the Bronx Democratic Party machine, has come under criticism for flip-flopping on the death penalty and police brutality.

The Democratic primary, like most post-Sept. 11, 2001, politics here, was a strangely attenuated affair. There was the occasional below-the-belt punch but little of the uninhibited nastiness that long defined city politics. All of the major candidates -- Weiner, City Council Speaker Gifford Miller and Manhattan Borough President C. Virginia Fields -- are liberal by national standards, and they found little to disagree about.

Voter turnout was low.

"They called an election, and almost no one showed up," said Henry Sheinkopf, a Democratic political consultant.

Bloomberg has been a technocrat's dream. His appointees are, by and large, well-regarded; he has cut through red tape to make it easier for residents to maneuver the bureaucracy; and during his tenure race relations have improved and crime has dropped. The mayor would not be mistaken for charismatic, but his nasal, Chamber of Commerce speaking style was almost soothing to some after a decade of Rudolph W. Giuliani's temple-throbbing theatrics.

But the mayor can sound a tad tone-deaf, dismissing manufacturing as a dying beast and insisting that New York is a "luxury item" and its residents should pay a premium for living in it. He has proved reluctant to tackle union work rules and tried unsuccessfully to build a football stadium on Manhattan's West Side.

"Bloomberg is a great technician, but he's missed a lot of opportunities," said Harvey Robins, a top aide to two former mayors.

This year's mayoral election will play out against a backdrop of economic and social change. Manhattan and Brooklyn are ever more gilded. The median income in Manhattan is nearly double that in the other four boroughs.

But many residents have a precarious hold on prosperity. The poverty rate rose last year to 20.3 percent (up from 19 percent in 2003), and a recent study found that the middle class shrank precipitously in the past five years while the percentage of those in the lower economic quarters grew.

"We have gone from a racialized city to a social-class-conscious city," Sheinkopf said. "The Democrats can make a race of this."

Fernando Ferrer, a former Bronx borough president, appeared to fall just short of gaining the 40 percent of the vote needed to avoid a runoff.