Mr. Trump, who spent the final weeks campaigning nonstop in red states where Democratic senators were vulnerable, including multiple visits to Florida, Indiana and Missouri, last came to Pennsylvania on Oct. 10 to stump for Mr. Barletta in Erie.
West of Pittsburgh, Mr. Lamb, who became one of the Democrats’ national darlings after winning a heavily pro-Trump district in a special election in March, defeated Representative Keith Rothfus, a Republican.
The House race considered the closest in the state was Mr. Fitpatrick’s, as he fought to portray himself as independent of the national party. He won endorsements from organized labor and gun control groups and was the beneficiary of around $7 million in outside spending by national Republican committees.
His Democratic opponent, Scott Wallace, a liberal philanthropist, told supporters the midterms were about “that crazy guy down there” in the White House.
At a high school in Warrington in Bucks County, it was clear that the backing of the liberal groups had boosted Mr. Fitzpatrick. Lindsay Edling, a 22-year-old waitress voting for the first time, said she generally prefers Democrats, but voted for Mr. Fitzpatrick because he had the support of two gun control groups. “Just all the shootings going on, it’s really been concerning,” she said.
And Susan Novick, 52, a special-education teacher, said she had voted for Mr. Fitzpatrick because his name was on the list given by the Pennsylvania State Education Association.
But it was also clear that Mr. Trump’s aggressively divisive campaign motivated some Republican and independent voters to cast a ballot for Mr. Wallace to send a message. “Don’t even ask me about Trump,” sneered Dorothy Brodsky, 73, a Republican who voted for Mr. Wallace. “I have 18 grandchildren. I’m very concerned about their future.”