NEW YORK — The Democrat aiming to unseat New York City’s rich and popular mayor, Michael Bloomberg, struggled to define himself in their final debate before Election Day, while Bloomberg kept him on the defensive.

Bloomberg, who finances his own campaign, has outspent William Thompson Jr. $85.2 million to $6 million, so far, and remains comfortably ahead by double-digits in the polls.

With a week to go until the election, the debate was Thompson’s last big chance to land a major punch on Bloomberg while also casting himself as a potential mayor rather than just an opponent.

But Thompson, the city comptroller, did not take advantage of several opportunities he had during the televised debate to talk about himself. At one point, when asked for specifics on why he’d be a better mayor than Bloomberg, Thompson answered by saying his opponent has squeezed middle class New Yorkers out of the city.

Thompson said he would “work to make sure that New York stays an affordable city,” but did not say how he would do so.

Bloomberg, meanwhile, kept up the strategy he has perfected — during the first debate, on the stump and in advertisements — of using negative attacks to shape Thompson’s image for voters rather than letting Thompson do it himself.

Bloomberg repeatedly sought to portray Thompson as an incompetent leader, as Board of Education president over the failing school system in the 1990s and as a mayoral candidate who has proposed billions of dollars of new spending without a way to pay for it.

“My opponent’s plans will raise taxes on everybody in this city and make this city a heck of a lot less affordable than it is today,” Bloomberg said.

Thompson has pledged not to raise taxes, but it is true that he has not provided specific revenue proposals to pay for his approximately $4 billion in new programs, like universal full-day pre-kindergarten.

And it isn’t fair to blame Thompson for the state of the schools when he was on the now-dissolved Board of Education from 1996 to 2001.

Thompson was one of several members who answered to a schools chancellor. That system was later replaced by one where the mayor is in charge.

The second debate between Thompson and Bloomberg, who is not registered with a party but is running on the Republican and Independence Party lines, was a little less contentious than their first faceoff two weeks ago.

Both candidates dedicated much of their time quoting what local newspapers have written about them, in articles as old as several months ago.

Thompson, for his part, tried to paint Bloomberg as an out-of-touch billionaire whose economic policies have been unfair to working people.

He pointed out that Bloomberg has also raised taxes, including in 2002 after he said he wouldn’t during his 2001 campaign, and other times during his eight years in office.

“New Yorkers have watched you increase taxes year after year after year,” Thompson said.

During one exchange, Thompson said his plan to bridge the city’s budget deficit — projected to approach $5 billion next fiscal year — is to cut out “waste and fat in government.”

Bloomberg responded that Thompson “was the comptroller for the last eight years, and if there was all this waste, it’s a shame he didn’t point it out back then,” he said.

Thompson was asked by a debate panelist whether he would give back campaign donations that came from investment managers who do business with the city. As comptroller, his job includes overseeing the municipal pension fund system.

He said there was nothing inappropriate about it, but Bloomberg pounced. It has been one of his campaign’s favorite issues.

“Why don’t you give back the money?” Bloomberg said. “It looks terrible, even if it’s not, and most people would think it is.”

Thompson turned the tables minutes later, suggesting that Bloomberg buys support with the hundreds of millions he gives away each year.

The mayor makes donations, Thompson said, “under the guise of, ‘Jeez I’m just doing good.’ The reality is, he’s doing it with the expectation of something in return.”