Trump’s schedule was meant to follow the traditional model of apolitical presidential visits with victims, law enforcement officials and hospital workers after calamities like the mass shootings that resulted in 31 deaths in Dayton and El Paso and that created a new sense of national crisis over assault weapons and the rise of white supremacist ideology.

That plan went awry even before Trump, who has acknowledged his discomfort with showing empathy in public, departed Washington. On Tuesday night, he attacked on Twitter the former Democratic congressman from El Paso, Beto O’Rourke, and as he prepared to leave the White House on Wednesday morning, he went after the former Vice President Joe Biden. Both men are running for president and have been particularly harsh in their criticism of Trump after the two shootings, and Trump rose to the bait.

The result was the latest example of Trump’s penchant for inflaming divisions at moments when other presidents have tried to soothe them, and further proof of his staff’s inability to persuade him to follow the norms of presidential behavior.

Trump himself finished the day claiming success. “We had an amazing day,” he told reporters in El Paso. Of his earlier stop in Dayton, he said: “The love, the respect for the office of the presidency — I wish you could have been in there to see it.”

Yet moments later, in response to questions about his Democratic critics, he again assailed them. “They shouldn’t be politicking today,” Trump said, referring to Biden and Sen. Sherrod Brown, D-Ohio, who accompanied Trump to a hospital in Dayton.

He was particularly upset by excerpts from a news conference in Ohio featuring Brown and Nan Whaley, the Democratic mayor of Dayton that he had seen while flying from Dayton to El Paso. Brown, who took an otherwise respectful tone toward the president, suggested that some victims at the hospital had privately complained about Trump’s visit and complained that he has used racist and divisive language.

Trump, who believes he has been treated unfairly by Democrats and the news media despite his remarks on Monday condemning white supremacy and other hateful ideology, reacted with fury. As his plane soared toward a restive El Paso, he bellowed at aides that no one was defending him, according to a person briefed on what took place.

Trump visited the two red-state cities after intense criticism that his fixation with illegal immigration has stoked white nationalism and that he has failed to take substantive action, including by backing substantial gun control measures, to combat mass shootings in the United States.

Trump was greeted by protesters in both Dayton and El Paso as well as by supporters defending him at a moment when conservatives say he is being unfairly blamed for tragedies committed by deranged individuals acting irrationally.

In Republican-leaning Dayton, Trump’s visit was met with small groups of protesters who waved signs that said “Dump Trump” and “Do Something!” Counterdemonstrators waved signs supportive of Trump.

The reception was especially bitter in El Paso, a border city that Trump has repeatedly criticized and where many people blame his anti-immigrant messaging and talk of a cross-border “invasion” for inspiring the gunman who killed 22 people at a Walmart here.

Protesters staged a daylong demonstration in a park near the University Medical Center of El Paso, and when Trump arrived at a nearby police emergency operations center, a group greeted him with a large white bedsheet that had the words “Racist, go home” written on it. At a memorial site in a parking lot near the Walmart, where mourners had erected small white crosses and left hundreds of flowers, balloons and candles, the appearance of a woman in a red “Make America Great Again” hat provoked shouting and profanity.

Although Biden spoke for many Democrats on Wednesday when he said in a speech that Trump has “fanned the flames of white supremacy,” Trump again denied that before he departed from Washington in the morning. But even as he did so, he repeated his past claim of equivalence between extremists on the left and right.

“I am concerned about the rise of any group of hate,” Trump told reporters before leaving the White House. “Any group of hate, I am — whether it’s white supremacy, whether it’s any other kind of supremacy, whether it’s antifa, whether it’s any group of hate, I am very concerned about it.”

That response had echoes of Trump’s characterization of an August 2017 white nationalist rally in Charlottesville, Virginia, that left a counterprotester dead. After initially condemning white supremacy, Trump later said that violence had been committed “on many sides.”

In recent days, Trump’s aides have also sought to draw attention to other acts of violence committed by people who have expressed leftist political views. But many current and former law enforcement officials are increasingly concerned that white nationalist violence is growing into a major domestic terrorist threat,

In his comments to reporters Wednesday morning, Trump repeated his previous attacks on unauthorized immigrants and called Biden, his leading Democratic presidential rival, “a pretty incompetent guy” who has “truly lost his fastball.”

The president held back from making any further public statements once he arrived in Dayton later in the morning, visiting privately with families and victims of the city’s weekend massacre as well as emergency and medical personnel at Miami Valley Hospital. But even as his spokeswoman said the event was never meant as a photo op, Dan Scavino, the president’s social media director, posted on Twitter pictures from inside the hospital “The President was treated like a Rock Star inside the hospital, which was all caught on video,” he tweeted. “They all loved seeing their great President!”

The White House quickly followed up with campaign-style video featuring images of Trump and the first lady, Melania Trump, shaking hands with first responders and chatting with smiling hospital workers.

Brown and Whaley joined Trump on the visit to the hospital, where they said they each pressed the president to take more aggressive action to pass universal background checks for gun ownership.

In a news conference soon after Trump departed Dayton for El Paso, Brown and Whaley said the president refused to commit to signing such a bill, but told them that he would “get things done.” Earlier in the day, Trump told reporters that he supported background checks, as he has before, but did not provide details about what legislation he might approve.

Brown said Trump “was received as well as you can expect by the patients.”

“They are hurting,” Brown said. “He was comforting. He and Melania did the right things. It’s his job in part to comfort people. I’m glad he did it.”

But later on Air Force One, Trump soon attacked the senator and the mayor on Twitter. “Their news conference after I left for El Paso was a fraud,” the president wrote. “It bore no resemblance to what took place.”

Scavino added on Twitter: “They are disgraceful politicians, doing nothing but politicizing a mass shooting, at every turn they can.”

In Dayton, the main protest of about a hundred people materialized along a stretch of South Main Street, in a grassy field a few blocks from the hospital where Trump was visiting some of the shooting victims.

Michael Prince, 55 — burly, tattooed and bushy-bearded — stood next to Jim Madewell, 71 — burly, tattooed and bushy-bearded — and watched the scene.

Madewell, a retired printing press foreman who said he lives 100 yards from the Dayton gunman’s house, said Trump’s language “throws gasoline on the fire,” and that leads to violence. “He feeds on negativity and hate and fear,” Madewell said.

As in Dayton, protesters gathered in El Paso before Trump’s arrival. Judy Lugo, the president of the Texas State Employees Union, said Trump should not have come.

“I don’t think it’s appropriate,” Lugo said. “The people here need to mourn, they need to be left alone.”

This article originally appeared in The New York Times.