Donald Trump says he will close down the US government if necessary to build his wall along the Mexico border.
The 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 much-criticised claim that "many sides" had to shoulder the blame for violence in Charlottesville, Virginia.
Mr Trump wants Congress to finance his controversial plan to build a "big, beautiful" wall along the United States' border with Mexico to keep out illegal immigrants.
But Republicans will need the support of Democrats to secure funding for the wall in a government spending bill, which they are unlikely to get.
In his speech, Mr Trump said the Democrats were "putting all of America's safety at risk" by opposing the wall. He said immigration officers who worked in the area said it was "vital" to stem the flow of illegal immigrants.
He said that, if it came to it, he would risk a government shutdown - which is what happens when legislation funding the federal government cannot be passed by Congress and non-essential services stop.
"Now the obstructionist Democrats would like us not to do it, but believe me if we have to close down our government, we are building that wall," Mr Trump said, adding that "the American people voted for immigration control".
If Mr Trump wants a government shutdown all he has to do is refuse to sign a funding bill sent to him by Congress.
Capitol Hill is set to debate a new budget measure this autumn, and unless it is passed federal operations will be in limbo by 1 October.
The prospect of a shutdown saw US stocks and the dollar weaken against both the euro and the yen. The S&P 500 Index was about 0.35 percent lower in afternoon trading. The Dow Jones Industrial Average was down by 0.33 percent and the Nasdaq Composite Index slid 0.38 percent.
Credit ratings agency Fitch said that if the country's debt limit was not raised in a timely manner, it would review the US sovereign debt rating, "with potentially negative implications". The rating is its measure of confidence in the soundness of the US economy.
Trump drops 'many sides' comment
Mr Trump attacked the media in the campaign-style speech, saying reporters 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 first public response to the violence on 12 August, which was criticised by both Republicans and Democrats for not explicitly condemning the far-right.
"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 his full quote was: "We condemn in the strongest possible terms this egregious display of hatred, bigotry and violence on many sides, on many sides."
Separately, the UN Committee on the Elimination of Racial Discrimination has criticised the US for what it said was a "failure at the highest political level" to reject "racist violent events".
Referring to Charlottesville, the committee said it was issuing a rare "early warning", which has been used in recent years in countries including Burundi, Iraq, Nigeria and the Ivory Coast.
'Scary and disturbing' rally
Responding to the speech, the former National Intelligence director James Clapper told CNN that he was questioning Donald Trump's "fitness" for office.
"I also am beginning to wonder about his motivation for it," he said, adding he found the rally "downright scary and disturbing".
Ruben Gallego, a Democratic Party congressman in Arizona, said it was the worst-ever speech by a US president. "It was all about him, it was not about the country," he told the BBC.
A former British ambassador to the US, Peter Westmacott, said he saw parallels with the establishment of Nazi Germany in 1933.
But Trump supporters were pleased.
"President Trump did an amazing job tonight. His message is uniting our great nation!", tweeted Ryan Fournier, the head of Students for Trump.
White nationalist Richard Spencer tweeted: "Trump has never denounced the Alt-Right. Nor will he."
- BBC