Fellow Democrats pounded mayoral front-runner Bill de Blasio in a debate last night — just hours after a new poll showed his support among city voters soaring above the pivotal 40-percent mark.

During the final televised showdown before next Tuesday’s primary, de Blasio’s four main opponents blasted his string of flip-flops — particularly on whether to extend term limits — as politically expedient.

“Why should the people of the city of New York believe you, Bill, given [that] your history . . . has been one of doing things in your political self-interest?” said former City Comptroller Bill Thompson.

“In the end, it comes down to a simple fact: What do you believe in? What are your core principles? If you believe in the people of the city of New York, then under no circumstance is it right to change term limits.”

De Blasio had supported a legislative change to extend term limits in 2005 when he was running for City Council speaker.

But after his speaker bid failed, he opposed Mayor Bloomberg when Hizzoner pushed for the extension in 2008.

At that point, de Blasio was eyeing another post — public advocate — and the two public referenda opposed the extension, foes said.

Disgraced former Congressman Anthony Weiner ripped de Blasio for his switch.

“This is a value question — you don’t change your values,” Weiner said. “I mean, you either believe it was offensive to overturn the will of the people legislatively or you don’t.”

A defensive de Blasio said his opposition in 2008 was sparked by the lack of public debate before the City Council voted to extend term limits from two terms to three.

“[Bloomberg] tried to ram his proposal through a very quick timeline,” said de Blasio, the public advocate. “He tried to use his money and power, and it was unfair to the people, and I led the opposition to it.”

But City Council Speaker Christine Quinn — who orchestrated the council’s vote for the extensions in 2008 — called her rival’s 2005 stance “a statement to get votes from council members.

“When you weren’t running for speaker anymore, you changed. It’s you talking out of both sides of your mouth,” she said.

The debate came as de Blasio won the backing of 43 percent of those surveyed by Quinnipiac University in a new poll — enough to avoid the runoff widely presumed just weeks ago to be a sure thing.

De Blasio’s support has climbed by 7 percentage points since a Q poll released last week.

His rivals were far behind.

Thompson had 20 percent in the latest survey, while one-time front-runner Quinn had 18.

Disgraced ex-Congressman Anthony Weiner was at 7 percent — down from 26 percent in late July — followed by City Comptroller John Liu at 4 percent and former Councilman Sal Albanese at 1.

Liu last night ripped de Blasio for bragging about his 11th-hour support of a “living-wage bill,” which requires companies receiving large city subsidies to pay their workers a minimum of $11.50 an hour.

“Bill, Bill, cut the nonsense here . . . You signed on at the very end to protect your own butt from the liberal and the progressive movement that was chiding you for opposing — or at least not supporting — that important living-wage legislation,” Liu said.

The comptroller also scored one of the biggest hits of the night by poking fun at de Blasio’s “Tale of Two Cities” campaign theme.

“We might not have a tale of two cities, but we’ll have a city of two tales,” under a mayor de Blasio, Liu said.

The battered public advocate responded, “I think what’s consistent is that I’m talking about the inequality facing our city.”

The hits contributed to criticism of the far-left candidate for his perceived hypocrisy, including involving a new case uncovered by The Post.

In late October, the public advocate put out a press release and did TV interviews supporting Mayor Bloomberg’s initial decision not to cancel last year’s NYC Marathon — despite the destruction of Hurricane Sandy.

After opposition mounted, de Blasio put out two press releases calling for the Nov. 4 event to be nixed.

Other cases of flip-flopping highlighted by de Blasio’s opponents include him:

* Benefiting from discretionary funds for years as a city councilman but recently denouncing the council’s allocation of the so-called “member items.”

* Refusing to sign a resolution as a city councilman to ban horse-drawn carriages but now saying it’s one of the first things he’ll do in office.

Meanwhile, on the Republican side, the new poll showed Joe Lhota far ahead of his competitors with the nod from 48 percent of GOP voters.

Supermarket magnate John Catsimatidis was at 24 percent, and Doe Fund founder George McDonald was at 10.

However, the poll surveyed only 101 likely Republican primary voters, leaving a margin of error close to plus or minus 10 percentage points.