Mayor Bill de Blasio easily defeated a field of longshot Democratic primary opponents Tuesday night, setting up a general election race against Republican Nicole Malliotakis.

De Blasio, seeking his second term in office, garnered about 75 percent of the vote, with nearly 85 percent of precincts reporting late Tuesday night, according to city Board of Election results.

Taking the stage at a Downtown Brooklyn nightclub with wife Chirlane McCray, and speaking in English and Spanish, de Blasio called the victory a “ratification of all we’ve been doing together,” but “we still need to build a fairer city.”

He now heads into the general election campaign with a nearly $5 million war chest, compared with Malliotakis, a Staten Island assemblywoman who entered the race in April, with $220,000 on hand.

De Blasio’s campaign contributions were eight times more than his four challengers combined — and he held a double-digit polling advantage.

His closest rival, Sal Albanese, an attorney and former city councilman, raised $200,000.

“I think we did a pretty good job,” Albanese told supporters gathered at a Park Slope eatery Tuesday night. “This was an effort where we were outspent almost 40-to-1 by this mayor and the political machines.”

In a July 27 poll conducted by Baruch College and NY1 news, 3.5 percent of Democrats said they would vote for Albanese compared with 57 percent for de Blasio.

The other primary candidates were police accountability activist Bob Gangi, entrepreneur Mike Tolkin and Brooklyn community board member Richard Bashner.

The Democratic contest failed to generate the same level of public interest as the 2013 primary that featured numerous high-profile contenders, including former Rep. Anthony Weiner, who was caught up in a sexting scandal.

Even in 2013, only 23 percent of the electorate voted.

Primaries typically attract a small turnout, and this year’s showing was expected to be especially low. Board of Elections spokeswoman Valerie Vazquez said on Tuesday afternoon that voter turnout in the city had been “light so far.”

The low turnout was evident at de Blasio’s Park Slope polling site, where he voted Tuesday morning. Unlike in past elections when the site was crowded with voters — including elections for de Blasio’s first bid for mayor in 2013 and those during last year’s presidential race — he didn’t have to wait in line because there wasn’t one.

Only four other voters were at the site in the neighborhood library basement as de Blasio and his wife, Chirlane McCray, walked downstairs, signed the register, greeted poll workers, filled out a scan sheet and left.

De Blasio, speaking outside the library after traveling from the mayoral mansion in Manhattan, said he wished more people would exercise their right to vote.

“I think it’s going to take some time to get people back in the habit,” he said. “That’s obvious.”

Albanese spent the day greeting voters in all five boroughs, unlike de Blasio, who only had one Brooklyn campaign stop on his schedule. Albanese, a self-described “underdog” has long acknowledged the difficulty of unseating an incumbent, but repeatedly said he remained in the race to give voters an alternative to de Blasio’s “four years of broken promises.”

De Blasio’s strongest support has come from black voters — his signature campaign ad in 2013 featured his son — sporting a towering Afro — discussing the NYPD. That support has stayed strong through his first term.

Interviewed at a senior center in predominantly black East New York, June Steinhauer, 73, said she voted for de Blasio because she believes he’s earned re-election.

“Nothing that he did really made me upset or feel disgruntled,” said Steinhauer, a retired subway tower operator, who is black and a longtime Democrat.

With Alison Fox