EL PASO — For days, President Trump tried to disprove critics who said he was incapable of uniting the nation after mass shootings in Texas and Ohio last weekend reignited the anger and pain over gun violence.

He denounced the white supremacist ideas that officials say apparently influenced a Texas man to target Latinos at a Walmart on Saturday, killing 22 people. He said that “hatred and mental illness pull the trigger,” when speaking of El Paso and Dayton, where nine people died. Before heading to the stricken cities Wednesday, he told reporters that he “brings people together” and wanted to “stay out of the political fray.”

As the president met with victims, posed for photos and tweeted residents that “we love you!” hundreds of protesters were in the streets not far away, holding signs that said, “No assault weapons,” “Stand up to the NRA” and “We can end gun violence.” Another simple message also appeared frequently: “Do something.”

The diverging reactions to Trump’s visit revealed the sharp divisions in the nation.

Though he skipped memorials at shooting sites, the president said he would “come up with something that’s going to be really good” to combat gun violence. He didn’t say what that would be, aside from a vague promise of stronger background checks. He said there was no “political appetite” for a ban on assault rifles like those used in the killings.

Then he logged on to Twitter on Air Force One and lobbed insults at “failed” Democratic Ohio Sen. Sherrod Brown and Democratic Dayton Mayor Nan Whaley. (Before leaving the White House, he also had sent a tweet slamming Texas Democrat Beto O’Rourke, who has said the president’s racist remarks are to blame for violence.)

The Trump visits Wednesday were the latest among his trips to mass shooting and disaster sites despite local opposition. In November, the president went to Paradise, Calif., after devastating damage from the Camp fire and anger over his inaccurate tweets criticizing fire management in the state.

Trump has faced the harshest critique for the El Paso shooting, where an anti-immigrant screed by the suspect echoed similar language that the president has used to say there is an “invasion” of Latino immigrants. The motive for the Dayton shooting remained unclear, but Trump has tried to paint the gunman — who was killed by police at the scene — as an extreme leftist. A Twitter account that appears to be linked to the shooter retweeted anti-police posts and those in support of anti-fascists.

In Dayton, Trump met with staff, victims and families at Miami Valley Hospital while demonstrators shouted outside. The hospital treated more than a dozen victims, most of whom have been released.

On Twitter, White House Press Secretary Stephanie Grisham said Trump told those at the hospital: “You had God watching. I want you to know we’re with you all the way.”

A similar scene took place in El Paso at the University Medical Center, where Trump also spoke to victims and staff. He later was driven to an emergency operations center.

Media representatives, who were not allowed to witness most of what happened during the visits, were told they were not “photo ops.” After his Ohio visit, the White House released a 50-second promotional video of Trump’s visit with background music and the slogan, “America Stands with Ohio!”

While Americans found out little about the how the president consoled those recovering from the tragedies, they found out plenty about his relationship with public figures in the cities.

At a news conference in Dayton with Whaley, Brown said the president “did the right things” at the hospital. “His job in part is to comfort people. I’m glad he did it in those hospital rooms,” said the senator, who joined Trump in the hospital with the mayor.

Whaley said she and Brown “reiterated to the president the importance of action around these issues and guns and that the people of Dayton are waiting for action from Washington, D.C.”

“A lot of time his talk can be very divisive,” Whaley said, “and that is the last thing we need in Dayton.”

The president took offense. He called the comments a “fraud.” White House aide Dan Scavino tweeted that they were “disgraceful politicians, doing nothing but politicizing a mass shooting, at every turn they can.”

In Texas, two of Trump’s two biggest critics this week avoided him altogether and attended an anti-Trump rally in sweltering heat at Washington Park.

“We are told to remain silent,” O’Rourke said. “We are standing up loud and proud to be counted with our fellow Americans as the best example of this country after one of the worst disasters she has ever seen.”

U.S. Rep. Veronica Escobar, a Democrat who represents El Paso, also attended after refusing to meet Trump after he would not speak with her about her request that he retract anti-immigrant and anti-Latino statements.

Priscilla Nevarez, 32, came to listen to O’Rourke and support the victims of the shooting and said she’d have preferred Trump stayed away from El Paso.

She stood with a sign crafted to look like a target that she could look through. It read, “Am I next?”

At the memorial outside the El Paso Walmart crime scene late Wednesday, scores of people gathered to pay their respects.

Some brought signs saying, “Go home devil” and “Trump go home.”

That upset Brenda Vigil, who found a fellow Trump supporter and a sign of their own, in red, white and blue: “Welcome Trump.” “He loves El Paso because El Paso loves him,” she said.

Kaleem reported from Los Angeles, Hennessy-Fiske and Montero from El Paso and Stokols from Dayton.