MIAMI—Former President Barack Obama on Friday accused his successor of employing a politically and racially motivated strategy to scare Americans in the final days of the 2018 midterm campaign about “folks that don’t look like we look.”

“The character of our country is on the ballot,” Obama told a majority-African-American crowd here in Miami’s Wynwood neighborhood. “In the closing weeks of this election, we have seen repeated attempts to divide us with rhetoric designed to make us angry and make us fearful.”

The former president, without explicitly mentioning President Donald Trump, was decrying Trump’s attempts to gin up fears over illegal immigration and the caravan of a few thousand migrants that is making its way toward the U.S.-Mexico border in an effort to get his most ardent supporters to the polls.

“It’s an old playbook. It’s one that the powerful and the privileged turn to whenever control starts slipping away,” said Obama. “They’ll get folks riled up just to protect their power and their privilege. Even when it hurts the country. Even when it puts people at risk. It’s as cynical as politics gets.”

Trump has referred to the migrant caravan as a “mob,” an “invasion,” and “an assault on our country” overrun with “some very bad people” and “unknown Middle Easterners.” He has floated the possibility of deploying as many as 15,000 American troops to the border. Obama called that a “political stunt,” adding: “The men and women of our military deserve better than that.”

On Thursday, Trump suggested that U.S. troops could fire at migrants if they throw rocks, a statement he walked back on Friday. Trump’s campaign further inflamed the immigration debate by releasing an online advertisement tying Democrats to a cop-killing immigrant who was in the country illegally. The ad was widely panned as racist. Trump has also promised to refuse asylum for the migrants and mused about ending birthright citizenship as guaranteed under the Fourteenth Amendment.

“They do this every election cycle—try to terrify folks—and then the election comes and the problem suddenly magically vanishes. You never hear about it again,” Obama said, comparing fears about the migrant caravan to those about immigrants coming across the border carrying the Ebola virus, an argument circulated by Republican candidates in 2014.

Obama—who was campaigning here alongside the party’s gubernatorial candidate Andrew Gillum, Sen. Bill Nelson, and other Democratic candidates—said Trump was telling voters that “order would be restored if it weren’t for folks that don’t look like we look, or love like we love, or pray like we do.” Trump, campaigning in the Fort Myers area on Wednesday, said Gillum would turn Florida into Venezuela. He has also called Gillum a “thief.”

The former president has been the subject of criticism among some Democrats for his reluctance to hit the campaign trail earlier in the 2018 cycle. He vehemently defended his legacy, including the passage of the Affordable Care Act. He attacked former Rep. Ron DeSantis (R-FL), Gillum’s opponent, for his several votes in favor of repealing the 2010 law.

The event featured statewide candidates in addition to Miami-area congressional candidates who are aiming to flip at least three Republican-held seats. Republicans are at risk of losing control of the House of Representatives, and are trying to grow their slim majority in the Senate by sending Trump to a half-dozen key states during the final stretch.

The ex-president appeared to enjoy being back on the campaign trail, frequently cracking jokes and bringing back his trademark call-and-response with voters inside the packed venue. He even poked fun at the handful of protesters who interrupted his remarks, at one point saying with a laugh: “This is what I look forward to, is having a few hecklers to get me back in the mood.”

“Why is it that the folks that won the last election are so mad all the time?” he asked.