MANCHESTER, N.H. — President Trump made his first visit to New Hampshire since the 2016 campaign on Monday, unveiling a plan to combat the opioid epidemic that includes a push for the death penalty for drug dealers and a crackdown on illegal immigrants.

Mr. Trump spoke in a state with the nation’s third-highest rate of deaths from overdoses and where opioids are a potent political issue. In a speech at a community college here, he offered up more tough talk than he did specifics about his plan, or how he would pay for it.

The president said that most of the heroin in the country comes in from the southern border, “where eventually the Democrats will agree with us and build the wall to keep the damn drugs out”; he denounced so-called sanctuary cities, which he blamed for an uptick in overdoses; and he called for harsher penalties for drug dealers.

“If we don’t get tougher on drug dealers, we are wasting our time,” Mr. Trump said, later adding, “That toughness includes the death penalty” — a position that was at odds with what White House officials told reporters on Sunday.