MURPHYSBORO, Ill. — President Trump said on Saturday that “the hearts of all Americans are filled with grief” after a mass shooting at a Pittsburgh synagogue left at least 11 people dead, and he called on the country to combat hate crimes together.

“It will require all of us working together to extract the hateful poison of anti-Semitism,” Mr. Trump said to a rally crowd here at an airplane hangar in rural Illinois. “The scourge of anti-Semitism can’t be ignored.”

Still, Mr. Trump again demonstrated that he would not be swayed from the call of the campaign trail during a politically volatile and violent midterm election season. Not as the death toll at the Tree of Life synagogue in Pittsburgh mounted. And not as the authorities were still investigating how another suspect in a separate case this week went from being a loyal Trump fan to mailing explosive devices to several of Mr. Trump’s critics.

In minutes, Mr. Trump moved from a call for unity to attacking and name-calling Democrats, including his former presidential rival, Hillary Clinton, and leading lawmakers like Senator Elizabeth Warren and Representative Maxine Waters.

Rather than hang back at the White House, the president barreled forward to Illinois to support Representative Mike Bost, a Republican in a tight race for re-election. Mr. Trump received counterterrorism briefings on the road. He delivered real-time shooting “results” to the country between Air Force One stops and urged Americans to fight religious and racial prejudice. And he repeatedly said that the death penalty should be enforced.

“We can’t make these sick, demented, evil people important,” Mr. Trump said to his rally crowd. “When we change all of our lives in order to accommodate them, it’s not acceptable.”

Asked by reporters beforehand about Cesar Sayoc Jr., who was arrested and charged with sending the explosives, Mr. Trump said, “He was no supporter of mine.”

On Saturday, Mr. Trump made a stop at an Indiana farming convention ahead of a busy schedule next week in the run-up to the elections, when at least 10 campaign events are scheduled. Mr. Trump also said that he intended to visit Pittsburgh, but did not give a time frame.

Hours before his latest rally — where he often voices his support of the Second Amendment — Mr. Trump said that the nation’s gun laws had “little to do” with the shooting and suggested that the synagogue should have had an armed guard in place.

“If they had protection inside, the results would have been far better,” he said. “This is a dispute that will always exist, I suspect.”

Four police officers were among the injured, according to Wendell D. Hissrich, Pittsburgh’s public safety director. And Democrats, including Pennsylvania’s governor, Tom Wolf, quickly disagreed with the president’s assertion that gun laws had little to do with the shooting.

“Dangerous weapons are putting our citizens in harm’s way,” said Mr. Wolf, adding that people should resist accepting “this violence as normal.”

President Barack Obama, who was sent one of the explosive devices this week, called for a retooling of gun laws, as did Democratic leaders in Congress.

“All of us have to fight the rise of anti-Semitism and hateful rhetoric against those who look, love, or pray differently,” Mr. Obama wrote on Twitter. “And we have to stop making it so easy for those who want to harm the innocent to get their hands on a gun.”

Senator Chuck Schumer of New York, the minority leader, described the shooting as “another terrible tragedy.”

The attack was even more painful because it occurred at “a place of sanctuary and prayer,” said Representative Nancy Pelosi of California, the House Democratic leader, offering prayers for the victims and calling for an overhaul of gun legislation.

“But thoughts and prayers are not enough,” she said. “Congress must finally act on common sense, bipartisan gun violence prevention legislation.”

Amid a growing outcry, the president seemed to soften his tone as the day went on, even as he disparaged Ms. Pelosi in Indiana and delivered a partisan political message in Illinois. As he crisscrossed the Midwest, he spoke with his eldest daughter, Ivanka Trump, and son-in-law, Jared Kushner, who are both Jewish.

By the time he addressed the crowd at the farming convention in Indianapolis, Mr. Trump called for “the vile hate-filled poison of anti-Semitism” to be condemned.

“This wicked act of mass murder is pure evil,” Mr. Trump said, adding that Americans should stand up to “any form of religious hatred or prejudice.” He also referenced news reports that indicated that the synagogue had been hosting a bris ceremony before the shooting took place.

“Our minds cannot comprehend the cruel hate and the twisted malice that could cause a person to unleash such terrible violence during a baby-naming ceremony,” Mr. Trump said. “This was a baby-naming ceremony at a sacred house of worship on the holy day of Sabbath.”

Both Mr. Trump and his vice president, Mike Pence, publicly suggested that the suspect, Robert D. Bowers, should pay the “ultimate price” for the shooting. On Saturday afternoon, Jeff Sessions, the attorney general, said in a statement that the Justice Department would file criminal charges against Mr. Bowers that could lead to the death penalty.

“Today 11 innocent people were suddenly and viciously murdered during religious services and several law enforcement officers were shot,” Mr. Sessions said. “These alleged crimes are reprehensible and utterly repugnant to the values of this nation.”

With 10 days to go until the midterm elections, the president at first wavered on whether to continue with his schedule on Saturday. He briefly considered canceling, but seemed ready to move forward after a rabbi and pastor delivered prayers onstage at the farmers’ conference. He said that his heart was not in it this time, but that he would attend out of “obligation.”

The president was not the only person in the Trump administration to hit the campaign trail after the shooting. Speaking at a rally in Las Vegas for Republican candidates running for office, Mr. Pence made reference to the mass shooting at a country music festival there a year ago, which left 58 dead.

“As Las Vegas knows all too well, what happened in Pittsburgh today was not just criminal, it was evil,” he said. “An attack on innocent Americans and an assault on our freedom of religion.”

At his rally, the president ended comments about the synagogue shooting by reiterating his belief that shooting suspects who target Jewish people should be put to death.

“Those seeking their destruction,” Mr. Trump said, “we will seek their destruction.”