PHOENIX – President Donald Trump on Tuesday threatened to shut down the government over border wall funding, said the North American Free Trade Agreement is likely to be terminated and signaled that he was prepared to pardon former Arizona sheriff Joe Arpaio, who is anathema to the Latino community.

Trump's freewheeling comments came during a boisterous campaign rally here during which he also went on an extended diatribe about the media, blaming reporters for the negative fallout he has received over his responses to the hate-fueled violence in Charlottesville.

Arpaio was convicted last month of criminal contempt for ignoring a federal judge's order to stop detaining people because he merely suspected them of being undocumented immigrants. A major Trump supporter during last year's campaign, he awaits sentencing.

"So was Sheriff Joe convicted for doing his job?" Trump asked the crowd. "You know what, I'll make a prediction: I think he's going to be just fine, OK? But I won't do it tonight because I don't want to cause any controversy. But Sheriff Joe should feel good."

Trump last week told Fox News that he was "seriously considering" a pardon for Arpaio and said he might do it soon, sparking speculation he would use Tuesday's campaign rally here to make the move.

In a speech that stretched well over an hour, Trump also expressed frustration with efforts to negotiate with Canada and Mexico to improve NAFTA, saying he was more likely to terminate the deal. He also blamed "obstructionist Democrats" for standing in the way of funding for a U.S.-Mexico border wall and suggested a government shutdown might be needed to force their hand. And Trump called for ending the filibuster rule requiring 60 votes for many issues in the U.S. Senate, a move that Republican leaders have refused to embrace.

At the outset of the rally, Trump selectively recounted the series of statements he made in the days following the melee in Charlottesville, arguing that he "spoke out forcefully against hatred and bigotry and violence" but that the media – whom he called "sick people" – refused to report it properly.

"You know where my heart is," Trump said, before pulling a copy of his first of three statements on the violence out of his suit coat and reading it to his audience. He later accused the media of giving a platform to the hate groups that were central to the violence in Charlottesville that led to three deaths.

Following his comments last week, Trump was criticized by Democrats and Republicans alike for blaming "both sides" for the violence and saying that "fine people" had marched along with white supremacists to protest the removal of a Confederate statue. He did not mention either of those remarks Tuesday.

The rally, organized by Trump's reelection campaign, came as the president continues to face criticism for his response to Charlottesville and feuds with fellow Republicans in Congress whose cooperation he will need to kick-start his sputtering legislative agenda next month.

Phoenix Mayor Greg Stanton, D, had urged Trump to not come to his city this week, saying that it was too tense of a time in the wake of the deadly Charlottesville clash between white nationalists and counterprotesters and that Trump could be setting the stage for more violent strife here. He also said that a pardon of Arpaio could make the situation even more dire.

Inside a partially filled Phoenix Convention Center, Trump was given a hero's welcome from supporters who chanted "USA! USA! USA!" and waved signs reading "Drain the Swamp," "Make America Strong Again" and "Make America Proud Again."

"You were there from the start, you've been there every day since, and believe me, Arizona, I will never forget it," Trump said at the start of his remarks, referencing a large crowd he drew at the site early in his campaign. His crowd Tuesday night numbered in the thousands but did not completely fill the hall at the convention center.

Before his arrival, Trump traveled to Yuma, where he received a closed briefing on border protection – something he touts as being among his administration's successes – and greeted Marines and their families, signing a couple of autographs on camouflage hats.

Trump was greeted at the airport by Arizona Gov. Doug Ducey, R, who was not expected to attend the rally. Nor were the state's two Republican senators, with whom Trump has been openly sparring.

There was a heavy police presence in downtown Phoenix, with law enforcement seeking to maintain civility between Trump supporters and detractors. Authorities used tear gas to disperse protesters after the rally ended.

About an hour before Trump was scheduled to arrive, hundreds of protesters gathered across the street, shouting, "This is what democracy looks like!" Metal barricades divided them from the red-capped people streaming into the rally, some grinning and waving.

A police officer wearing a helmet and bulletproof vest could not say how many people had come to demonstrate against the president's visit. "A lot," he offered.

Uzma Jafri, a 40-year-old doctor from Phoenix, walked through the crowds of Trump supporters and protesters with a backpack of medical supplies. She said she came here to quickly treat anyone if violence broke out.

"My ethical background, and my moral background, is to assist anyone who needs it – regardless of if they hate me," said Jafri, who poured a bottle of water over her black hijab in the 107-degree heat.

Brian Ratchford came to the event armed with a .357-caliber gun to defend Trump supporters if things got out of hand

"He's an American for Americans," said Ratchford, 47, of Tucson. What Trump said after Charlottesville "was perfect – people on both sides were causing the problems," said Ratchford, who had been outside the convention center since 10 a.m.

Tuesday night's event was part of a familiar pattern for Trump.

When he finds himself under attack or slipping in popularity, he often holds a rally in a place like this: a diverse blue city that's home to liberal protesters but surrounded by red suburbs and rural towns filled with Trump supporters who will turn out in droves.

It happened in the first weeks of his presidential campaign, when he was dismissed as a sideshow and criticized for his comments on undocumented immigrants – only to be greeted by thousands of fans, along with protesters, at a rally at the convention center.

Then in March 2016, when Trump grew frustrated that he still had not become the presumptive Republican nominee, he planned a massive rally in inner-city Chicago that attracted thousands of supporters but was canceled at the last minute because of the high number of protesters. This March, when his presidency seemed constantly under attack, Trump held a rally in Nashville that attracted at least 2,500 protesters.

Unlike rallies in states that are solidly Republican, these events allow Trump to highlight the deep division in the country – and force voters to pick a side.

In Phoenix, campaign organizers expected more than 10,000 supporters to show up at the convention center on Tuesday night, and numerous counterprotests were planned for outside the rally. Local activists said they hoped to outnumber the rallygoers, sending a clear message to the president after the Charlottesville rally this month that attracted neo- Nazis and white supremacists.

"By coming here in a time of national crisis and a national question of where people stand, he is doubling down on his bigotry, continuing to race-bait and speak to his base," said Carlos García, executive director of Puente Arizona, which advocates for migrants.

Phoenix is home to some of the most organized progressive activists in the country, and they have provided a much-studied example of how to fight at a grass-roots level to challenge lawmakers and change policies that target undocumented immigrants. The Phoenix area gave liberals one of their few victories last November: The ouster of Arpaio, the longtime Maricopa County sheriff, who was accused of encouraging his deputies to employ racial profiling and enforce federal immigration laws in the Phoenix suburbs.

In July, Arpaio was convicted of criminal contempt in Arizona for ignoring a judge's order to stop detaining people because he merely suspected them of being undocumented immigrants. His sentencing is scheduled for Oct. 5, and he faces up to six months in prison.

Last week, Trump told Fox News the former sheriff is a "great American patriot" who has "done a lot in the fight against illegal immigration." Arpaio told CNN that he had not been invited to attend the Tuesday night rally.

White House press secretary Sarah Huckabee Sanders told reporters traveling with the president Tuesday that Trump was not planning to announce a pardon for Arpaio at the rally.

"There will be no discussion of that today at any point, and no action will be taken on that front at any point today," she said.

A pardon – whenever it might come – would be likely to ignite the anger of hundreds of activists who spent more than a decade peacefully pushing for change through traditional channels, as well as the voters who chose not to reelect him.

"A pardon for Joe Arpaio is a pardon for white supremacy," Jess O'Connell, chief executive of the Democratic National Committee, said at a news conference here Monday.

Early Tuesday morning, local authorities closed streets near the convention center and installed barricades along the sidewalks aimed at keeping protesters separated from rallygoers.Many businesses and government buildings downtown closed early.

In the hours before the rally, as Trump supporters lined up outside the convention site, a police officer on his motorcycle drove by, repeatedly offering this instruction: "Folks, please drink water. If you wait until you're thirsty, it's too late."

Protest organizers said one challenge would be managing the hundreds of people not affiliated with their groups who showed up wanting to make a statement. Organizers and local lawmakers were urging a peaceful demonstration.

However, there were clashes after the rally, and police eventually used smoke canisters to disperse the crowds. No injuries were immediately reported.

While Democrats and immigration rights activists have been holding news conferences and speaking out against the president this week, Republicans have been quiet. No one answered the phone at the Arizona GOP offices on Monday or Tuesday.

Arizona's two Republican senators, John McCain and Jeff Flake, have at times been critical of the president. Trump has tweeted praise of Kelli Ward, a former state lawmaker with far-right views and a long-shot Senate candidate who is challenging Flake.

In the hours leading up to the rally, a few dozen Ward supporters were out on the streets wearing yellow T-shirts reading "TRUMP 2016/WARD 2018" on the front and "MAKE ARIZONA GREAT AGAIN" on the back.

This was Trump's ninth rally in the state – and his fourth at the Phoenix Convention Center.

His first event at the convention center was on July 11, 2015, a few weeks after he announced he was running for president and gave a rambling speech that cast undocumented immigrants as criminals and "rapists."

Although those remarks prompted criticism and led several corporations to cut their business ties with him, the support for his campaign was evident in Phoenix, where he had to upgrade to a larger venue and then still had to turn away many supporters – a showing that shocked many Arizonans.

—