WILKES-BARRE, Pa. — President Trump rallied supporters here Thursday for Republican Senate candidate Lou Barletta in a test of the president’s ability to bolster the chances of GOP allies in crucial swing states in November’s midterm election.

Trump spent most of the 80-minute rally hailing his own achievements, re-litigating his 2016 victory and what he considers the news media’s unfair coverage of it, and criticizing the press corps.

In the moments in which he focused on the midterm election, Trump cast Sen. Robert P. Casey Jr. (D-Pa.), whom Barletta, a House member, is trying to unseat, as a liberal in thrall to Democratic leaders who are determined to undermine the president’s agenda, including tougher immigration policies and the nomination of Brett M. Kavanaugh to the Supreme Court.

“Bob Casey is against every one of the things I just said,” Trump said. He ridiculed Casey and predicted that Barletta would “destroy” him if the two were to debate.

“That will be great entertainment,” Trump said, after telling the crowd that he would sit in the front row if it were to happen.

Barletta, who represents this northern Pennsylvania hamlet, joined Trump on stage briefly, to extol the economic growth under Republican leadership and question why voters would risk turning over control of Congress to Democrats.

“Why would we ever stop that?” Barletta said. “We’re not tired of winning, Mr. President!”

The rally came as the president is ramping up his travel before the midterm elections. He appeared in Tampa on Tuesday night to support the gubernatorial bid of Rep. Ron DeSantis (R-Fla.) and will head to Ohio’s Delaware County on Saturday to try boost GOP state Sen. Troy Balderson’s prospects in a special election Tuesday.

Trump delivered his remarks Thursday at the Mohegan Sun Arena at Casey Plaza, a stadium that can hold 10,000, which he visited twice during his 2016 presidential campaign. In an illustration of how important the race is to the White House, Vice President Pence also visited the state last week on behalf of Barletta.

Barletta, a former mayor of Hazleton, Pa., was elected to the House in 2010 on a tea party wave, after rising to prominence through his tough stance on illegal immigration — an ethos the president shares. And he was one of the earliest Republican lawmakers to support Trump, who values personal loyalty above almost all else.

Last week, Trump tweeted his support for Barletta, touting his position on immigration. “He is tough on Crime and Borders,” Trump wrote. “Will be a great Senator from Pennsylvania. His opponent is WEAK on Crime, ICE and Borders. We need Lou!”

In recent weeks, the president has helped pull other Republicans to victory in contested primaries. But Barletta, some Trump allies privately say, is not an ideal challenger to Casey, who leads him in fundraising and polls.

One of Trump’s most prominent, high-profile disappointments came in the state, when Republican Rick Saccone, his preferred candidate in a special election in April for a House seat west of Pittsburgh, narrowly lost to Democrat Conor Lamb.

Nonetheless, Pennsylvania still occupies a hallowed place in the Trump psyche, and the president was eager to return, aides said. The state, with its 20 electoral votes, was critical to Trump’s victory over Democrat Hillary Clinton in 2016, and his rallies here, especially in the Wilkes-Barre area, were among the most raucous of the campaign.

Rust Belt swaths of the state such as Luzerne County, where Wilkes-Barre sits, were particularly critical for Trump, who seized the White House, in part, by persuading union and working-class Democrats to vote for him. Although he won Pennsylvania only narrowly, he earned nearly 58 percent of the vote in Luzerne Country — which flipped Republican after supporting Barack Obama in 2008 and 2012.

Trump also attended the University of Pennsylvania’s Wharton School — an Ivy League credential about which he frequently boasts.

The president alluded to that connection during his remarks, and he spent most of the first 10 minutes talking about watching returns come in on Election Night in 2016 and seeing that he would win Pennsylvania.

“The fake news refused to call it,” Trump said, prompting chants of “CNN sucks” from the crowd.

Trump repeatedly lambasted the news corps during his remarks, saying that he received unfair coverage of his recent summit meetings with North Korean leader Kim Jong Un and Russian President Vladi­mir Putin, as well as for his visits to a NATO summit and Britain.

“They can make anything bad, because they are the fake, fake disgusting news,” Trump said, before returning to the subject of the evening.

“All right,” he added, “let’s get back to some boring subjects — like Bob Casey.”

Nakamura reported from Washington.