“What was the name?” Mr. Trump asked. “Animals!” his cheering supporters screamed back.

“If you want your communities to be safe, if you want your schools to be safe, if you want your country to be safe, then you must go out and get the Democrats the hell out of office,” Mr. Trump said. “Democrats have opposed every common-sense measure necessary to stop this horrendous scourge of crime, to dismantle MS-13 and to stop illegal immigration.”

Mr. Trump was in Nashville to boost Representative Marsha Blackburn, a Republican, who is running to succeed Senator Bob Corker, who is retiring. He savaged Phil Bredesen, the state’s former Democratic governor whom Ms. Blackburn is expected to face in November, calling him “an absolute, total tool of Chuck Schumer,” the Senate Democratic leader, and “of course, the MS-13 lover Nancy Pelosi,” he said, referring to the House Democratic leader.

Both criticized Mr. Trump after he made the “animals” comment, and Ms. Pelosi said, “You have to wonder, does he not believe in the spark of divinity, the dignity and worth of every person?”

Mr. Trump’s appearance in Nashville was a new phase of heightened campaign activity for the president as he looks toward the midterm elections, keeping an early focus on the deeply conservative states he won handily in 2016 and steering clear of politically competitive areas where his presence could be riskier. Ms. Blackburn has tethered herself tightly to Mr. Trump in her bid, a vital race for Republicans working to hold off Democratic attempts to seize the majority.

During an hourlong performance before a huge American flag, Mr. Trump plainly relished his time in front of the cheering crowd, regaling them with stories of what he argued were unmatched successes as president, and drifting off script for brash asides.