WAYNESBURG, Pa. — The stakes are high for President Trump and congressional Republicans in Tuesday’s special election to fill a U.S. House seat, with GOP leaders unnerved about the prospect of defeat and the implications for this year’s midterm elections.

A loss in Pennsylvania’s 18th Congressional District — a working-class slice of the country that Trump has cultivated as his political base — could shatter hopes that his core voters will turn out in droves this fall and save the GOP’s 24-seat House majority.

And, coming days after the president announced tariffs on steel and aluminum imports, the vote could raise fresh questions about the power of Trump’s protectionist agenda to lift his party.

“It really is a test that sets things in motion,” former Republican National Committee chairman Michael Steele said. “Does the base have energy? Does the party have the structure and discipline it needs?”

But the cause has divided Republicans.

Inside the White House, Trump and his aides have dismissed suggestions that the contest is a referendum on him and have berated GOP candidate Rick Saccone, 60, for running a sluggish campaign against Democrat Conor Lamb, 33, according to three Republicans who were not authorized to speak publicly.

One GOP official said Saccone, a state representative, has been a “failure” due to his lackluster campaigning and reliance on Trump — and coolly added that Lamb, a former Marine, has been clever in sharing aspects of Trump’s stances and running as an outsider in courting Republican voters.

“He’s running like he’s a friend of Trump,” former Pennsylvania congressman Bob Walker (R) said. “That approach, plus the fact that some Democrats in these areas are coming home, makes it competitive.”

Lamb has closed his bid with care. At campaign stops, the youthful former prosecutor never mentions Trump. When former vice president Joe Biden visited, it was Biden, not Lamb, who took questions.

“Let me tell you what kind of Democrat Conor is,” Cecil Roberts, president of the United Mine Workers of America, said at Lamb’s rally Sunday. “He’s a God-fearing, union-supporting, gun-owning, job-protecting, pension-defending, Social Security-believing, health care-creating, and sending-drug-dealers-to-jail Dem­o­crat!”

Conservative groups have spent more than $10 million in the race, and Trump rallied a crowd here over the weekend, underscoring the desire to emerge victorious and calm GOP lawmakers who have seen a spate of retirements and only grown more wary of their reelection chances since Democrats won a U.S. Senate seat in Alabama in December.

Republicans said Monday that the surge of drama in what they had expected to be a relatively sleepy race has revealed significant issues nationally for Trump and the party.

“It should wake everybody up,” Rep. Peter T. King (R-N.Y.) said. Win or lose, “it should be a warning signal that Republicans have to do a better job explaining our policies and not live in an echo chamber. The people who hate Trump will come out, but what about the people who like him?”

Saccone spent the final day of the campaign alongside Donald Trump Jr., with the candidate and the president’s eldest son donning hairnets for a kitchen tour of Sarris Candies in Canonsburg. Trump Jr., who went to high school and college in Pennsylvania, said he wanted to spotlight a business that had grown from 320 to 400 employees following passage of the GOP-authored tax law last year.

Asked about Republican criticism of Saccone’s campaign, Trump told reporters, “God knows, if it’s going to make it difficult for Trump, the media’s going to be all over it.”

At the candy plant, Tony Ross, 72, said he remained undecided. He was intrigued by Lamb after his former union, the United Steelworkers, endorsed him, and by the Democrat’s support for the president’s new steel tariffs.

“It’s like a death in the family when a steel plant closes down,” Ross said. “But I haven’t seen anything in Saccone’s record that stands out for unemployed people.”

Darlene Bales, a 67-year-old factory employee, pointed at Saccone during the tour. “If he doesn’t win, lock him up!” she said.

Polls show a close race, but Saccone dismissed the numbers. “You guys have been up and down with poll numbers,” he said. “We’re out meeting people every day, and everywhere I go, it’s 100 to 1 for Rick Saccone.”

Trump won the district by nearly 20 percentage points against Democrat Hillary Clinton in 2016. The 18th includes suburban towns south of Pittsburgh and has a mostly white electorate. The special election was called after representative Tim Murphy, a Republican, resigned in disgrace last year following the disclosure of an extramarital affair during which the antiabortion congressman seemed to suggest that his mistress should seek an abortion.

“You can’t read too much into these special elections. That’s why they call them special,” former Trump campaign adviser Ed Brooker said, reflecting the mood of Trump’s political circle on the eve of the election. “You have to focus on what the candidates there are doing.”

The victor will serve out the remainder of Murphy’s term, but the district will cease to exist in its current form in November, due to the Pennsylvania Supreme Court redrawing the state’s congressional map.

Lamb’s moderate streak has won converts. Linda Miller, 74, said that she and her husband left their presidential ballots blank in 2016, and that she had not voted for a Democratic nominee since Bill Clinton. Trump, she said, had “brought some jobs back,” but Lamb had won her over after saying he would not support House Minority Leader Nancy Pelosi (D-Calif.) in a leadership race.

“I haven’t seen anything she’s done in there that’s any good,” Miller said. “We need a young person in there who’s going to be honest.”

Frank Snyder, general secretary of Pennsylvania’s AFL-CIO, challenged reporters at Lamb’s Sunday rally to follow the rental cars of Republican operatives who have come to the district to turn out voters.

“They’ve got Tennessee plates. They’ve got Virginia plates. They’ve got plates from Washington, D.C.,” Snyder said.

Still, veteran Pennsylvania Democrats are cautious about predicting an upset.

“Lamb has outraised Saccone, but it’s the outside money where the Republicans have the advantage,” former Pennsylvania governor Ed Rendell said. “The incredible Republican spending is going to have an effect, even though Lamb has been smart in not letting the race get nationalized like we saw in the special congressional election in Atlanta last year.” In that vote in Georgia’s 6th Congressional District, Democrat Jon Ossoff was defeated by Republican Karen Handel (R).

Saccone’s pitch has been less about touting the Republican tax law and more about embracing Trump at every turn. But that hasn’t stopped outside GOP groups such as the Congressional Leadership Fund, a super PAC aligned with House Speaker Paul D. Ryan (R-Wis.), from running a flurry of ads criticizing Lamb for opposing the Republican tax effort and tying him to Pelosi.

At the president’s Saturday rally, many attendees said they remained steadfast in Trump’s corner despite his controversies, giving party leaders confidence that the tariff push and Trump visit could keep the seat red.

On stage, Trump warned them that he could make progress only “if we elect people who are going to back our agenda.”

James Johnson, 42, had a one-word reason for why he planned to vote for Saccone on Tuesday: “Republican.”

“I think we need to keep the country going in the direction it’s going in,” said Johnson, a Trump-supporting union member who works in manufacturing. He credited Trump for his paycheck going up about $100 a month since Republicans passed their tax law — and said that’s enough for him.

Jenna Johnson contributed to this report.