Democratic presidential candidate New York City Mayor Bill de Blasio prepares for a television interview Thursday before the second night of the first Democratic presidential debate. (Joe Raedle/Getty Images)

New York City Mayor Bill de Blasio’s campaign finally had some momentum.

Fresh off a strong showing in the first Democratic presidential debate in Miami on Wednesday, de Blasio continued to shore up his liberal bona fides. He visited a children’s migrant shelter Thursday morning and lambasted the Trump administration’s treatment of immigrants. That afternoon, he joined a rally for workers on strike at Miami International Airport.

“We should be putting working people first,” he told the crowd, which roared its approval.

But then, the mayor broke “the most obvious rule of Miami politicking.” He quoted the extraordinarily divisive revolutionary Ernesto “Che” Guevara, who many in the city’s Cuban expat community consider murderous and tyrannical for helping Fidel Castro establish his communist regime.

“Hasta la victoria, siempre,” de Blasio declared. At the protest, the call — which translates to “Until victory, always” — won him more cheers. But the backlash came hard and fast, as those on the left and right criticized de Blasio for quoting one of the most widely reviled figures in Miami.

The head of the state’s Democratic Party wrote on Twitter that de Blasio “does not speak for Floridians or the Florida Democratic Party and he would be wise to apologize.”

Shortly thereafter, de Blasio did just that.

“I did not know the phrase I used in Miami today was associated with Che Guevara & I did not mean to offend anyone who heard it that way,” de Blasio said in a tweet. “I certainly apologize for not understanding that history. I only meant it as a literal message to the striking airport workers that I believed they would be victorious in their strike.”

Florida state Sen. Annette Taddeo (D), who spoke at the strike before de Blasio, said she was “utterly disgusted” with his remark.

“This is completely unacceptable!” she wrote on Twitter. “How can anyone wanting to be the leader of the free world quote a murderous guerrilla - in Miami no less! A community filled with his victims!”

Meanwhile, Republicans who have sought to paint Democrats as radical leftists seized on de Blasio’s slip-up. Sen. Rick Scott (R-Fla.) tweeted, “In case there was any doubt about the Democrats running for President embracing socialism, @BilldeBlasio is in Miami quoting . . . Che Guevara. You can’t make this up.”

His fellow Florida Republican, and the country’s most famous Cuban American politician, Sen. Marco Rubio (R-Fla.), suggested that de Blasio knew precisely who he was quoting, noting the Democrat’s early activism and his time spent studying Latin American politics in college.

A 2013 New York Times investigation chronicled the then-mayoral candidate’s bygone admiration for Nicaragua’s ruling Sandinista party in the 1980s (de Blasio has since criticized the group’s tactics).

The article describes him during a trip to Nicaragua in 1988: “He spoke in long, meandering paragraphs, musing on Franklin D. Roosevelt, Karl Marx and Bob Marley. He took painstaking notes on encounters with farmers, doctors and revolutionary fighters.”

He also honeymooned in Cuba, the Times reported, in violation of a United States travel ban.

“But he had NO IDEA he was quoting Che Guevara today,” Rubio wrote Thursday evening. “It was all just an incredible coincidence.”

The misstep came at an inconvenient time for de Blasio, whose debate performance had injected some badly needed excitement into his six-week-old campaign.

Last month, a Quinnipiac University poll revealed some ominous numbers for the New Yorker’s campaign: His net favorability was worse than every other Democratic candidate. Last week, numbers from a Suffolk University-USA Today poll didn’t look much better: Just 11 percent of respondents were excited about his candidacy, while more than 4 in 10 hoped he’d drop out of the race.

Even so, his brash style — honed in the rough-and-tumble political landscape of the country’s largest city — won him sweeping praise in the hours after the debate, the primary’s first major proving ground.

The Washington Post’s Aaron Blake declared de Blasio one of the night’s “winners.” Blake wrote: “He was on his game: He cut in to get more time. He talked about having hard conversations with his black son. He talked about his dad’s PTSD, which eventually led to suicide. And he made perhaps the most far-reaching case for government activism outside of [Sen. Elizabeth Warren (Mass.)] — exactly as he wanted.”

A headline from BuzzFeed News read “Bill De Blasio . . . Actually Maybe Knows What He’s Doing.” One in Slate said, “Bill de Blasio Had a Surprisingly Not Bad Night.”

After only 30 minutes, the filmmaker Michael Moore lauded his performance — although he also conceded: “No one predicted that.”

But de Blasio has argued that he makes a convincing case for his party’s nomination. He’s a self-styled liberal and a champion of union rights with a background in executive-level politics.

“When was the Democratic Party strong? For decades, when we were clearly the party of working people and we did really bold things to change people’s lives,” he said in a Thursday interview with CNN’s Wolf Blitzer. “What I’ve done in New York, I want to do for the whole country.”

That was his objective during the airport rally, he said, to stand in solidarity with workers who said they weren’t being fairly treated or compensated. He apologized again for quoting Guevara and said he hadn’t understood the phrase’s origin.

“Nothing wrong with apologizing,” Blitzer told the candidate. “As our moms and dads always told us, you make a mistake, you go ahead and apologize.”

“Amen,” de Blasio responded. “They taught us well.”