Incumbent Bill de Blasio, polling ahead of all rivals by double digits and raising millions more than all challengers combined, went head-to-head in a debate Wednesday with Sal Albanese, his main but longshot rival for New York City’s Democratic mayoral nomination.

De Blasio, 56, who is seeking a second term, has all but avoided a competitive primary through the power of incumbency, and initially refused to commit to a primary debate ahead of the Sept. 12 primary election.

Albanese, 67, questioned whether de Blasio has done enough to fulfill the promise of his winning 2013 campaign slogan — to end the Dickensian “Tale of Two Cities,” and make New York City more affordable.

“I don’t know what planet Bill de Blasio is living on,” Albanese said, responding to de Blasio’s claims that his affordable housing plan has made inroads in addressing the city’s affordable housing crisis.

“Sal’s been out of public life for more than 20 years,” de Blasio said of the former city councilman who last held office in 1998. De Blasio added: “Your facts are off.”

The candidates sparred over de Blasio’s stewardship — a homelessness spike the mayor is struggling to wrangle, a crumbling subway system the state controls, his tendency to travel nationally and internationally and his fundraising practices.

Albanese refused to give the mayor credit for a continuing crime decline despite predictions when de Blasio was elected four years ago that his left-leaning platform would plunge the city into dystopia.

“If Mickey Mouse was the mayor, we’d still have crime going down,” Albanese said.

De Blasio sought to defend his administration from the shadow of multiple investigations by prosecutors who probed his fundraising practices. The mayor said he was “exonerated,” which Albanese noted was at odds with what the U.S. attorney said in March when the office announced de Blasio wouldn’t be prosecuted.

De Blasio’s team, the prosecutor’s office said, fielded requests from favor-seekers “after which the mayor made or directed inquiries to relevant city agencies on behalf of these donors.”

Albanese said de Blasio isn’t doing enough to reduce the number of homeless people living in shelters; it’s more than 60,000.

De Blasio countered that he’s doing his best. “It’s a battle that’s going to take a long time to win.”

The mayor suggested he would veto a package of City Council legislation called the Right to Know Act that would require NYPD officers to identify themselves by name, rank, assignment and other details when a person is stopped and no arrest is made. De Blasio, to the consternation of some allies on the left, said the best way to make changes with the NYPD was not via legislation.

De Blasio often found himself on the defensive during the debate — a handful of hecklers in the audience shouted “liar!” as the mayor claimed that he had kept the city’s housing affordable to residents of modest means, and the audience often laughed as Albanese took shots at de Blasio.

"If Bill de Blasio gets re-elected... the best job in the city will be to serve as the mayor’s travel agent," Albanese said taking aim at de Blasio’s trips to Germany, and throughout the United States to advocate Democratic causes.

De Blasio defended his out-of-state travels, saying his predecessors also “had to work on the national stage ... to protect the initiatives that millions of New Yorkers depend on.”

Albanese, who served on the City Council for 15 years starting in 1983, and who has run unsuccessfully for mayor in 1997, 2000, and 2012, earned a spot on the debate stage by raising at least $175,000 in campaign contributions required under the city’s matching funds program. De Blasio has raised $4.8 million.

Among Democrats, 57 percent would vote for de Blasio, with 3.5 percent picking Albanese, according to a poll released July 27 by Baruch College and NY1 news.

Outside the debate hall, Symphony Space on Manhattan’s Upper West Side, a carnivalesque scene overtook Broadway before the start of the 7 p.m. debate: a costumed Big Bird flanked by former NYPD detective and independent mayoral hopeful Bo Dietl, ridiculed de Blasio, who Dietl likens to the “Sesame Street” character; police and jail critic Bob Gangi, who was barred from the debate because he didn’t raise enough money, held a mock debate with a broomstick topped with a Red Sox hat; de Blasio’s labor union supporters chanted “Four more years!”

A second debate is slated for Sept. 6.