“I challenge you, Donald Trump, to come to New York City, and I will debate you about what’s right for New York City and BuzzFeed can host it,” Mr. de Blasio said. “Because he doesn’t understand New York City, and when his presidency is over really soon, he will not be welcome back in New York City.”

Before he was an official candidate for president, Mr. de Blasio told voters in Iowa that Democrats would not win back the White House by focusing on Mr. Trump. He criticized Hillary Clinton, his former boss and Democratic nominee for president, for pursuing such a strategy.

Most observers see Mr. de Blasio’s change of heart as part of a recognition that he needs to find a way to draw attention to himself as one of the last candidates to enter the race, one of the lowest in the polls and one of the worst fund-raisers.

The only problem? It’s not working.

“Mr. de Blasio keeps on looking for something magical that will allow him to break through,” said Kenneth Sherrill, a professor emeritus of political science at Hunter College. “You keep on throwing bombs until one works or either your arm falls off. You have to admire his doggedness.”