RENO, Nevada — President Donald Trump called for unity in a speech at the American Legion’s 99th National Convention here, just hours after a raucous campaign-style rally in which he lambasted the media and his political rivals, and reignited the controversy over his response to a white supremacist rally in Charlottesville this month.

“It is time to heal the wounds that have divided us, and to seek a new unity based on the common values that unite us,” Trump said Wednesday, speaking before more than 5,000 members of the largest veterans group. “We are one people, with one home, and one flag.”

“We are not defined by the color of our skin, the figure on our paycheck or the party of our politics,” Trump continued.

Trump argued that “shared humanity,” “citizenship” and patriotism could heal the nation’s divides political and racial divides and he heralded the work of the Legion in promoting American values.

Trump’s remarks come at a time when he is facing continued pressure to stem the divisions exposed by a deadly rally in Charlottesville, Virginia, this month, which was organized by hate groups including the Ku Klux Klan and neo-Nazi sympathizers.

The comments were a sea change from Trump’s posture hours earlier at a rally in Phoenix on Tuesday night, at which he angrily railed against the “dishonest” media for its coverage of his remarks on the Charlottesville gathering. Initially, he had blamed “many sides” for the conflict, rather than criticizing the collection of Ku Klux Klan, white supremacist and neo-Nazi groups that planned the event.

His first statement was widely condemned, including by lawmakers in his own party, prompting Trump to issue new, scripted comments that named the hate groups. But even after correcting his initial remarks, Trump reverted back to his original stance, claiming at a news conference later in the week that there were “fine people” among the hate groups who had gathered to protest the removal of a Confederate statue.

In his campaign rally, Trump reread his comments on the Charlottesville remarks, but omitted the words “many sides.”

And he blamed the media for accusing him of being racist.

“I hit him with neo-Nazi. I hit them with everything. I got the white supremacists, the neo-Nazi. I got them all in there, let’s say. KKK, we have KKK. I got them all,” Trump said in Phoenix. “So what are they saying, right? It should have been sooner. He’s a racist. It should have been sooner, OK.”

Trump also 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.

CNN reported Wednesday that the White House had prepared paperwork for Arpaio’s pardon.

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 Tuesday. “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.”

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 suggesting 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 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 after 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.

The rally in Phoenix on Tuesday, organized by Trump’s re-election 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, a Democrat, 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.

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.

In Reno on Wednesday, Trump appeared to stick to his carefully crafted script, focusing on his administration’s efforts to improve services for veterans, a key focus on the nation’s largest veterans organization.

After his speech, he signed into law the Veterans Appeals Improvement and Modernization Act, which reforms the process by which veterans can appeal their claims for disability benefits with Veterans Affairs.

“I promised you that I would make it my priority to fix the broken VA and to deliver to our veterans the care they so richly deserve,” Trump said. “And you see what’s been happening.

“Now you have a true reformer in Secretary David Shulkin.”

Shulkin served as undersecretary of Veterans Affairs for health under President Barack Obama before he was named secretary by Trump in January.

But Trump’s response to the racial divisions in the country hung over his appearance here before a group of veterans that included some who fought against Nazism and fascism in World War II.

The day before Trump’s appearance, the Legion voted to reaffirm a nearly 100-year-old resolution condemning hate groups.

The resolution states that “the American Legion considers any individual, group of individuals, or organizations, which creates, or fosters racial, religious or class strife among our people, or which takes into their own hands the enforcement of law, determination of guilt, or infliction of punishment, to be un-American, a menace to our liberties, and destructive to our fundamental law.”

Trump was expected to hold up the values espoused by the Legion as an example of how the country can begin to unite.

“We are here to hold you up as an example of the strength, courage and love that our country will need to overcome every challenge that we face,” Trump said. “We are here to draw inspiration from you as we seek to renew the bonds of loyalty that bind us together as one people and one nation.

“If American patriots could secure our Independence, carve out a home in the wilderness, and free millions from oppression around the world, that same sense of patriotism, courage and love can help us create a better future for our people today,” he added.

Despite the controversy, veterans have long been supportive of Trump generally.

Among those who gathered to hear Trump’s remarks at the convention, some were sympathetic to his approach to the Charlottesville controversy.

“He’s not a very delicate guy. He never says things in a very delicate way,” said Ed Riley, a retired Navy fighter pilot who began serving in 1970. “I never heard him ever endorse any of the far right.

“It always upsets me when the news says this was a white supremacist thing. It was not, it was nationalist — a white nationalist [thing],” Riley added.

Washington Post writers John Wagner, Jenna Johnson, Danielle Paquette, Lourdes Medrano and Philip Rucker contributed to this report.