• The office has a budget of $3.5 million, and can introduce legislation and hold public hearings.

How did Mr. Williams win?

Mr. Williams had a big advantage over his opponents: His spirited but unsuccessful challenge last fall to Lt. Gov. Kathy Hochul bolstered his name recognition in the five boroughs.

In the public advocate contest, Mr. Williams easily defeated the second-place finisher, Councilman Eric Ulrich of Queens.

The race, however, had two jolts that were seen as potential roadblocks to Mr. Williams’s victory:

• First, the Amazon deal collapsed, giving Mr. Ulrich — a Republican and a prominent supporter of the plan — an opening to win over voters upset that the company would not be employing about 25,000 people on a new Queens campus.

• Then, mere days before the election, a previously undisclosed 2009 arrest of Mr. Williams was leaked to the news media. Mr. Williams said he did nothing wrong, characterizing the altercation as a “verbal disagreement” with his girlfriend at the time.

Still, Mr. Williams attracted 33 percent of the vote. Mr. Ulrich, his nearest competitor, had 19 percent of the vote.

Get ready for more voting.

Mr. Williams will serve only through the end of this year. To hold on to the position through 2021, he needs to win a primary election in June and the general election in November.