Bill de Blasio, who transformed himself from a little-known occupant of an obscure office into the fiery voice of New York’s disillusionment with a new gilded age, was elected the city’s 109th mayor on Tuesday.

His landslide victory, stretching from the working-class precincts of central Brooklyn to the suburban streets of southeast Queens, amounted to a forceful rejection of the hard-nosed, business-minded style of governance that reigned at City Hall for the past two decades and a sharp leftward turn for the nation’s largest metropolis.

Mr. de Blasio, the city’s public advocate, defeated Joseph J. Lhota, a former chairman of the Metropolitan Transportation Authority, by a margin of about 49 percentage points, with 99 percent of the vote counted.

It was the most sweeping victory in a mayor’s race since 1985, when Edward I. Koch won by 68 points, and it gave Mr. de Blasio what he said was an unmistakable mandate to pursue his liberal agenda.