EL PASO, Texas -- Aiming to play the traditional role of healer during national tragedy, President Donald Trump paid visits to cities reeling from mass shootings that left 31 dead and dozens more wounded. But his divisive words preceded him, large protests greeted him and biting political attacks soon followed.

The Republican president and first lady Melania Trump flew to El Paso late Wednesday after visiting the Dayton, Ohio, hospital where many of the victims of Sunday's attack in that city were treated. For most of the day, the president was kept out of view of the reporters travelling with him, but the White House said the couple met with hospital staff and first responders and spent time with wounded survivors and their families.

Trump told them he was "with them," said press secretary Stephanie Grisham. "Everybody received him very warmly. Everybody was very, very excited to see him." Trump said the same about his reception in the few moments he spoke with the media at a 911 call centre in El Paso.

But outside Dayton's Miami Valley Hospital, at least 200 protesters gathered, blaming Trump's incendiary rhetoric for inflaming political and racial tensions in the country and demanding action on gun control. Some said Trump was not welcome in their city. There were Trump supporters, as well.

In El Paso, former Rep. Beto O'Rourke spoke to several hundred people at a separate gathering. O'Rourke, a potential Democratic 2020 presidential rival, has blistered Trump as a racist instigator, but he also told those in his audience the open way the people of his hometown treat each other could be "the example to the United States of America."

Emotions are still raw in both cities in the aftermath of the weekend shootings. Critics contend Trump's own words have contributed to a combustible climate that has spawned death and other violence.

The vitriol continued Wednesday.

Trump's motorcade passed El Paso protesters holding "Racist Go Home" signs. And Trump spent part of his flight between Ohio and Texas airing his grievances on Twitter, berating Democratic lawmakers, O'Rourke and the press. It was a remarkable split-screen appearance for TV viewers, with White House images of handshakes and selfies juxtaposed with angry tweets.

Trump and the White House have forcefully disputed the idea that he bears some responsibility for the nation's divisions. And he continued to do so Wednesday.

"My critics are political people," Trump said as he left the White House, noting the apparent political leanings of the shooter in the Dayton killings. He also defended his rhetoric on issues including immigration, claiming instead that he "brings people together."

Some 85% of U.S. adults believe the tone and nature of political debate has become more negative, with a majority saying Trump has changed things for the worse, according to recent Pew Research Center polling. And more than three quarters, 78%, say that elected officials who use heated or aggressive language to talk about certain people or groups make violence against those people more likely.

In Dayton, raw anger and pain were on display as protesters chanted "Ban those guns" and "Do something!" during Trump's visit.

Holding a sign that said "Not Welcome Here," Lynnell Graham said she thinks Trump's response to the shootings has been insincere.

"To me he comes off as fake," she said.

Dorothee Bouquet, stood in the bright sun with her 5-year-old daughter and 2-year-old son, tucked in a stroller. She told them they were going to a protest "to tell grownups to make better rules."

But in El Paso, where more protests awaited, Raul Melendez, whose father-in-law, David Johnson, was killed in Saturday's shooting, said the most appropriate thing Trump could do was to meet with relatives of the victims.

"It shows that he actually cares, if he talks to individual families," said Melendez, who credits Johnson with helping his 9-year-old daughter survive the attack by pushing her under a counter. Melendez, an Army veteran and the son of Mexican immigrants, said he holds only the shooter responsible for the attack.

"That person had the intent to hurt people, he already had it," he said. "No one's words would have triggered that."

Local Democratic lawmakers who'd expressed concern about the visit said Trump had nonetheless hit the right notes Wednesday.

"He was comforting. He did the right things and Melania did the right things. It's his job to comfort people," said Sen. Sherrod Brown, who nonetheless said he was "very concerned about a president that divides in his rhetoric and plays to race in his rhetoric."

"I think the victims and the first responders were grateful that the president of the United States came to Dayton," added Mayor Nan Whaley, who said she was glad Trump had not stopped at the site of the shooting.

"A lot of the time his talk can be very divisive, and that's the last thing we need in Dayton," she said.

Grisham, responding on Twitter from aboard Air Force One, said it was "genuinely sad" to see the lawmakers "immediately hold such a dishonest press conference in the name of partisan politics."

President @realDonaldTrump graciously asked Sen Brown & Mayor Whaley to join as he and the First Lady visited victims, medical staff & first responders. It is genuinely sad to see them immediately hold such a dishonest press conference in the name of partisan politics. https://t.co/BB0lXhfBnG — Stephanie Grisham (@PressSec) August 7, 2019

Despite protests in both cities, the White House insisted Trump had received positive receptions. One aide tweeted that Trump was a "rock star" at the Dayton hospital.

The White House did not allow reporters and photographers to watch as he talked with wounded victims, medical staff and law enforcement officers there, but then quickly published its own photos on social media and released a video of his visit.

There was discord in El Paso, too. Rep. Veronica Escobar, the Democratic congresswoman who represents the city, declined to meet with Trump. "I refuse to be a prop," she said in an interview on CNN.

Visits to the sites of mass shootings have become a regular pilgrimage for recent presidents, but Trump, who has sometimes struggled to project empathy during moments of national tragedy, has stirred unusual backlash.

Though he has been able to summon soothing words and connect one-on-one with victims, he often quickly lapses into divisive tweets and statements -- just recently painting immigrants as "invaders," suggesting four Democratic congresswoman of colour should "go back" to their home countries even though they're U.S. citizens and deriding majority-black Baltimore as a rat-infested hell-hole.

As the presidential motorcade rolled up to a 911 centre in El Paso, it passed a sign aimed at Trump that said "Racist go home."

Elsewhere in the city, O'Rourke told several hundred people that his hometown "bore the brunt" of hatred from the shooting but could also hold an answer to the strife.

On the eve of his trip, Trump lashed out at O'Rourke, saying he "should respect the victims & law enforcement - & be quiet!"

Beto (phony name to indicate Hispanic heritage) O’Rourke, who is embarrassed by my last visit to the Great State of Texas, where I trounced him, and is now even more embarrassed by polling at 1% in the Democrat Primary, should respect the victims & law enforcement - & be quiet! — Donald J. Trump (@realDonaldTrump) August 7, 2019

On his flight between one scene of tragedy and the second, Trump said he tuned in as another 2020 rival, former Vice-President Joe Biden, excoriated him in a speech that slammed him as incapable of offering the moral leadership that has defined the presidency for generations and "fueling a literal carnage" in America.

Trump declared the speech "Sooo Boring!" and warned that "The LameStream Media will die in the ratings and clicks" if Biden wins.

Watching Sleepy Joe Biden making a speech. Sooo Boring! The LameStream Media will die in the ratings and clicks with this guy. It will be over for them, not to mention the fact that our Country will do poorly with him. It will be one big crash, but at least China will be happy! — Donald J. Trump (@realDonaldTrump) August 7, 2019

Trump seemed focused on politics through the day. He mentioned the crowd at his earlier rally in El Paso. When a reporter asked what he saw during the day, he answered with claims about how he was received respectfully in both cities. Then on the flight home he unleashed another political tweet:

"The Dems new weapon is actually their old weapon, one which they never cease to use when they are down, or run out of facts, RACISM! They are truly disgusting!"

The Dems new weapon is actually their old weapon, one which they never cease to use when they are down, or run out of facts, RACISM! They are truly disgusting! They even used it on Nancy Pelosi. I will be putting out a list of all people who have been so (ridiculously) accused! — Donald J. Trump (@realDonaldTrump) August 8, 2019

------

Associated Press writer John Seewer contributed to this report. Colvin reported from Washington.