LOUISVILLE, Ky. — President Trump, embattled in Washington, traveled here on Monday to deliver a rollicking populist and nationalist appeal, promising to rewrite trade agreements, clamp down on illegal immigration and keep terrorists out of the country — all in the service of putting “America first.”

In a speech ostensibly timed to push the Republican health care law through Congress, Mr. Trump drew deeply on the themes that animated his 2016 campaign, whipping up a rapturous crowd with promises to reopen shuttered coal mines and throw lawless immigrants out of the country.

Mr. Trump promised that health care legislation would undo the “disaster” of President Barack Obama’s Affordable Care Act. But he presented it less as a cornerstone of his legislative agenda than as a necessary prerequisite to finance deep tax cuts.

“We have to get this done to do the other,” Mr. Trump declared.

For Mr. Trump, who is enduring one of the most difficult stretches of his young presidency, the rally was a chance to bathe in the adulation of a campaign crowd, a sea of people waving placards that said: “Buy American. Hire American” and “Promises Made. Promises Kept.”