ESTERO, Fla. — At President Trump’s rally in Florida on Wednesday night, the state’s Republican candidate for the Senate, Gov. Rick Scott, took the stage to thank the president for his help in recovering from a pair of hurricanes, avoiding Trump’s more divisive actions.

Trump didn’t take the hint, however, and in this heavily Latino state plowed ahead with an attack on his latest immigration target, the “crazy policy” of birthright citizenship, while Scott moved offstage. In contrast, the Republican running to succeed Scott as governor, Ron DeSantis, praised Trump and echoed the president’s attacks against his Democratic opponent, Tallahassee Mayor Andrew Gillum, prompting chants of “Lock him up!”

Trump’s latest foray into Florida, a large and culturally diverse state, underscored the complications of his persistent presence in the final days before Tuesday’s election. His efforts to stoke fears of an immigrant “invasion,” for example, are likely to galvanize supporters and detractors alike. His erratic responses to last week’s pipe-bomb threats and synagogue massacre haven’t helped.

The president can help drive Republican turnout, which could help a polarizing candidate like DeSantis. At the same time, he poses a potential liability for Republicans in states with large Latino populations who are pursuing a different strategy — including Scott, who has spent months courting Florida’s large Puerto Rican community — as well as for House candidates in more moderate suburban districts nationwide.

Party strategists and nonpartisan analysts say Trump’s closing strategy shows he has largely given up on Republicans keeping control of the House and is instead focusing on Senate contests and, to a lesser extent, governors’ races.

A number of Senate races remain close, but they mostly are in states where Trump is popular. Indiana, Montana, West Virginia and Missouri, where Democrats are seeking reelection, rank high on Republicans’ target list, and they top the president’s campaign travel destinations.

But he is avoiding states like Pennsylvania and Wisconsin that were critical to his victory in 2016. Though he has campaigned in each state, he is now considered a potential drag on Republican candidates in competitive races, particularly for the House. He is also steering clear of California, where Republicans have no Senate candidate but a number of vulnerable Republican-held seats.

Though Trump has chosen his rally locations carefully, he has sought to make immigration the top issue nationwide. This week, he proposed to end the constitutional right to citizenship for people born in the U.S., an idea aimed at parents who are here illegally; ordered thousands of troops to border states, and released a political ad that even some Republicans called racist, linking Latino immigrants to cop-killers and blaming Democrats for letting killers into the country.

On Thursday, he delivered another immigration speech, a televised address at the White House that hadn’t been on his schedule when the day began.

Trump largely reiterated claims that the caravan of migrants from Central America, still hundreds of miles from the U.S. border, was “like an invasion.” He suggested he’s instructed troops they can fire on migrants who throw rocks, an act that would not justify deadly force under Pentagon rules.

“To take those hard-line, core right-of-center positions only plays well to the Senate piece of this puzzle,” said David Paleologos, a nonpartisan pollster who has conducted surveys in key states including Florida. “A lot of his alleged haphazard tweets and comments are really well-thought-out, poll-driven actions.”

Paleologos said he believes that Scott, running slightly behind incumbent Democratic Sen. Bill Nelson in several recent polls, is one of the few Republican Senate candidates who could be hurt by Trump’s strategy. Democrats concede that Trump is probably helping Senate candidates in key states.

“There’s no other organizing principle among Republicans other than President Trump nowadays, and getting them out and motivated for an election is really impossible without the president,” said Democratic pollster Matt Canter.

But Canter said Trump’s outsized presence on the campaign trail and his polarizing immigration rhetoric could prove “extremely helpful” to Democratic challengers in as many as 20 House races, almost enough seats for their party to win a majority. Several of those contests are in Pennsylvania, where suburban women who stuck with Trump in 2016 appear to be deserting him — and his party’s candidates.

“Two years ago, he had kind of an across-the-board appeal in certain demographics. I’m not sure that’s there this time,” said Charlie Gerow, a Pennsylvania-based Republican consultant.

Trump’s approval rating in the Keystone State sits at 36% and Democrats held a 53% to 38% advantage when registered voters were asked which party’s congressional candidate they would choose, according to a new poll released Thursday by Franklin & Marshall College.

That survey also showed the Republican Senate candidate in Pennsylvania, Trump ally Lou Barletta, trailing Democratic Sen. Bob Casey by 15 percentage points. Trump has appeared in the state several times in recent months, but appears to have given up.

“The president likes to be in places where he can make a difference and then declare his presence was a key factor,” said Mike DeVanney, a Republican media consultant based in Pittsburgh. “And I don’t see too many opportunities for that to be the case here in Pennsylvania.”

In Wisconsin, Republican Senate candidate Leah Vukmir has wholly embraced Trump and trails by double-digits. Gov. Scott Walker, a Republican fighting hard for a third term, has lost support in the crucial Milwaukee suburbs, home to educated, white voters who have largely been turned off by the president’s divisive politics.

Trump held a rally last week in the small town of Mosinee, in rural northern Wisconsin, home to just 4,000 people. While the president remains overwhelmingly popular with registered Republicans, he gets a negative rating from 55% of the independent voters Walker has been courting desperately, according to a new Marquette University poll this week.

Trump’s final campaign swing has him campaigning in solidly Republican parts of mostly red states with hot Senate and gubernatorial races, including Columbia, Mo., on Thursday night; Huntington, W.Va., and Bozeman, Mont., on Friday; and Macon, Ga., and Chattanooga, Tenn., on Saturday.

While he’s staying away from Democratic-leaning states and many suburban House districts, Republicans in such places still struggle to keep their distance.

In New York’s Hudson Valley, Rep. John Faso seemed less than pleased that the president had — without warning — endorsed his reelection on Twitter. “I didn’t know it was coming,” Faso told The Times. “You know, it is what it is. It’ll help with some people and hurt with others.”

Rep. Mike Coffman, a Republican who represents suburban Denver and trails his Democratic challenger in recent polls, has made a point of criticizing Trump’s policies and personal behavior in a last-ditch effort to survive.

His strategist, Josh Penry, remains upbeat but said Trump’s closing message — which fills local airwaves even without a presidential visit — doesn’t make things easier.

“In the last week, the president has behaved like a guy trying to build a permanent political majority in the Ozarks,” he said. “The purposeful provocation on immigration just makes an already grim situation in suburbs even more difficult.”

Stokols reported from Estero, Fla. Bierman reported from Washington. Times staff writers Jennifer Haberkorn contributed from Belleville, Ill., and Evan Halper from Kingston, N.Y.