But it also showed the value of picking candidates — in Mr. Saccone, 60, a social conservative who was not the natural choice for many suburban Republicans, and in Mr. Lamb, a telegenic 33-year-old former Marine.

“You have to give credit,” Mr. DeVanney said. “He was clearly the best candidate they’ve run for this district. And not only the best candidate but he executed a strong campaign.”

Some residents, even those who considered themselves Trump supporters, thought that most voters on Tuesday were only considering their disapproval of the president. The candidates themselves were more or less irrelevant.

“Lightweights, the both of them,” said Gary Berman, 75, a retired engineer sitting in the food court of the upscale South Hills Village shopping mall. The area had changed, he said. The older people had been moving away to retire, while younger — and more liberal — people moved in.

“They hate Trump,” he said of the newcomers. “That’s all that matters.”

Other Republicans were not convinced it was so simple. They did not deny the energized antipathy toward Mr. Trump, which arguably made this campaign competitive in the first place. But in such a tight race, there are still factors the candidates control that can sway the outcome.

Samuel DeMarco, a Republican who sits on the Allegheny County Council, kept returning to what he saw as Mr. Saccone’s missteps — poor fund-raising, missed events, the lack of a clear vision — particularly in contrast to the adroitness of Mr. Lamb.

Mr. DeMarco saw little campaigning by Mr. Saccone on the two policy matters he could have championed — the tax plan that the Republicans passed in December and the planned steel tariffs — and instead saw a pitch that boiled down to little more than his support of Mr. Trump.