As simple as that sounds, it should not detract from Mr. Lamb’s feat. The 18th Congressional District runs from the rural southwest corner of the state, a blue-collar wedge of gas fields and coal mines, up to the middle- and upper-class Pittsburgh suburbs, a mix of dependably Democratic communities and Republican strongholds.
Many political experts had focused on whether Mr. Lamb could keep the vote close in rural areas, something he accomplished with a strong pitch to labor unions. But the scale of his margins in some suburbs was what surprised many, and likely pushed him over the top. Voters in the suburbs have also helped Democrats in other recent races, particularly in Alabama, where the Democrat, Doug Jones, beat the Republican favorite, Roy Moore.
Mr. Trump easily won Bethel Park in 2016; four years earlier, Mitt Romney racked up a 24-point win in Upper St. Clair, the affluent township next door. On Tuesday, Mr. Lamb, whose campaign signs dot the manicured lawns, won both by 10 points.
Mike DeVanney, a Republican political consultant in Pittsburgh, saw several things at work in Mr. Lamb’s campaign, all of which are warning signs for Republicans in the midterm races in November. For many, he said, this was “the first opportunity to voice an opinion on Donald Trump,” and that opinion, at least among the most motivated, was not favorable.
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.
“I don’t think the Saccone campaign ever gave the public a compelling reason to vote for him,” he said. “This is a Saccone thing when it comes to Republicans. It’s a Trump thing when it comes to Democrats.”
Still, the distinction is not always so clear. For Janet Supko, 63, a retired schoolteacher who voted for Mr. Trump in 2016, the election was all about the president.
“There have got to be some changes made,” said Ms. Supko, who had just rounded the corner of Macy’s in her morning walk at South Hills Village. While she had benefited from the Republican’s income tax overhaul, she lamented the president’s “lack of professionalism,” the numerous hirings and firings, and the general sense of chaos in the White House.
Mr. Lamb was young and fresh and new; maybe he represented the change she had been hoping for when she voted for Mr. Trump in the first place.
“Sometimes,” she said, “you just have to try something else.”
Her walking partner, Clare Rex, 68, was never a fan of Mr. Trump, but for her, in the end, the election was about Mr. Lamb.
“I saw him at the fish fry at Our Lady of Grace,” she said. “He just seems to bring a fresh perspective.”
The women came to the end of their walk at the Starbucks, where they met two friends, both Republicans, both Trump supporters, and neither surprised by what happened on Tuesday. Whether it was because of the Lamb campaign’s savvy or anti-Trump energy on the Democratic side, they said, the win for Mr. Lamb, even here in a place that had not voted Republican in years, seemed inevitable.
Over the weekend, Christine Sorbara, 72, had gone to President Trump’s rally in an airplane hangar in support of Mr. Saccone. She thought it probably helped him some. But around the district, she said, if it wasn’t Lamb yard signs, it was his supporters knocking on doors.
“I saw Lamb, Lamb, Lamb,” she said.