Donald Trump has vowed to close down the government if necessary to build his wall along the Mexico border.
The US president told supporters at a “Make America Great Again” rally in Phoenix, Arizona, that the opposition Democrats were being “obstructionist”.
During the 80-minute speech, he also took aim at the media, blaming them for giving far right groups “a platform”.
But he selectively quoted his initial response to violence at a far-right rally that left one woman dead.
He omitted the controversial claim that “many sides” had to shoulder the blame for violence in Charlottesville, Virginia.
In his wide-ranging speech, Mr Trump also said he thought he would “probably end up terminating Nafta”, the trade deal with Mexico and Canada.
On North Korea, the president sounded a hopeful note about the possibility of a reduction in tensions over Pyongyang’s missile tests and nuclear programme.
Referring to North Korean leader Kim Jong-un, Mr Trump said: “I respect the fact that he is starting to respect us”.
“And maybe – probably not, but maybe – something positive can come about,” he added.
But while his comments were met with cheers inside the conference centre, anti-Trump protesters who had gathered outside the rally clashed with police after the rally had finished.
Police deployed tear gas after the protesters threw bottles and rocks, Reuters news agency reported.
President Trump began and finished his speech by urging the American people to come together.
But he quickly turned on familiar foes, beginning with the media, which he said had misrepresented his “perfect” words in the wake of the violence in Charlottesville, where Heather Heyer was killed after a car ploughed into a crowd of people protesting against far-right demonstrators including neo-Nazis.
He accused “truly dishonest people in the media and the fake media” of “trying to take away our history and heritage” because, he said, they “don’t like our country”.
He quoted his own initial public response to what happened in Charlottesville.
“This is what I said on Saturday: ‘We’re closely following the terrible events unfolding in Charlottesville, Virginia,’ – this is me speaking. ‘We condemn in the strongest possible terms this egregious display of hatred, bigotry and violence.’ That’s me speaking on Saturday, right after the event,” he said.
But what he actually said on 12 August was: “We condemn in the strongest possible terms this egregious display of hatred, bigotry and violence on many sides, on many sides.”
Mr Trump’s attention then turned to immigration, and to the Democrats who he said were “putting all of America’s safety at risk” by opposing the wall he wants to build along the US’s southern border with Mexico.
He said immigration officers who worked in the area said it was “vital” to stem the flow of illegal immigrants.
Mr Trump concluded: “If we have to close down government, we are building that wall.”
Mr Trump also used the rally to hint he would pardon controversial former Arizona sheriff Joe Arpaio, a man who rose to national prominence because of his tough stance against illegal immigration.
He told the crowd Mr Arpaio – who was found guilty of criminal contempt in July – “is going to be just fine”, but would not formally pardon him at the moment because “I don’t want to cause any controversy”.
His comments directly contradicted those of White House spokeswoman Sarah Sanders, who said on Tuesday “there will be no discussion of that today”.
Mr Arpaio, 85, was found to have violated a judge’s 2001 order that he cease detaining migrants who are not suspected of having committed a state crime.