Republicans kept their grip on the House of Representatives on Tuesday, overcoming months of efforts by Democrats to tarnish them by association with Donald J. Trump in what proved to be a grave miscalculation.
With a handful of races outstanding Wednesday morning, Democrats had a net gain of just five seats and were expected to remain in the minority, a position they have occupied since Republicans swept to power in 2010 on a wave of Tea Party fervor.
In the few districts that changed hands, it was not perennially endangered Republicans in typical swing districts who were falling, but rather some incumbents who had been comfortably re-elected in the past.
In an early victory, Democrats toppled Representative John L. Mica, a Florida Republican who had cruised to re-election since coming to Congress in 1993. Mr. Mica was defeated by Stephanie Murphy, a business professor and former national security specialist. Ms. Murphy was able to take advantage of a district that had been redrawn.
In another redrawn Florida district, encompassing St. Petersburg, Charlie Crist, the former Republican governor turned Democrat, defeated Representative David Jolly.
In New Jersey, Representative Scott Garrett, a conservative Republican who just finished his seventh term, lost to Josh Gottheimer, a former Clinton administration speechwriter.
And Democrats eyed Representative Darrell Issa’s once-safe seat in Southern California, hoping to bring down the former chairman of the House Committee on Oversight and Government Reform, one who relished his role as an Obama administration antagonist. By Wednesday morning, his race was still too close to call, with the possibility that it would not be called for days. (The state’s vote-by-mail system allowed voters to postmark their ballots as late as Tuesday.)
There was no doubt that Democrats would pick up seats this year, chipping away at the Republicans’ 247-member majority, their largest since the 1930s. But Democrats ultimately fell well short of expectations. Nonpartisan estimates had anticipated House Democrats could pick up between five to 20 out of about two dozen seats considered up for grabs — most of them held by Republicans.
The possibility that Democrats could gain at least 30 seats and retake the majority was always considered far-fetched.
As it became clear that Republicans could not only hold both chambers but also claim the presidency, Republicans who had braced to lose all but the House began entertaining notions of a sweep. That would open the possibility of the passage of the party’s long-stalled agenda, Representative Tom Cole of Oklahoma said Tuesday night.
“If that happens, then you’ll see a lot of major legislation moving quickly, I think, in January and February,” he said. “We’re going to have to justify a majority like this.”
The volatility of the presidential race infused a dash of unpredictability into the final weeks of the election. As Republicans scrambled last month to respond to a 2005 recording in which Mr. Trump boasted in vulgar terms about sexually assaulting women, the hopes of Democrats soared.
But the wave of Republican losses that Democrats had hoped for proved more a ripple, with vulnerable Republicans like Representative Barbara Comstock of Virginia holding their ground in districts where Mr. Trump’s popularity seemed to be foundering for most of the race.
It appeared the decision by some Republicans to distance themselves from Mr. Trump did not harm them, and perhaps even saved them in some districts. Ms. Comstock, who represents the nation’s wealthiest district, said little about Mr. Trump until the recording became public, becoming one of the first in her party to disavow him because of it. She won a close race after Democrats hammered her for what they said were her policy similarities to Mr. Trump, a strategy employed against other endangered Republicans. Hillary Clinton won her district.
Carlos Curbelo, a freshman representative of Florida, who had been outspoken against Mr. Trump throughout his race, held his seat in a re-election battle that pitted him against Joe Garcia, whom he defeated two years ago. Democrats spent more than $2 million to try to reclaim the hotly contested district. Mr. Trump won his district.
Perhaps more than the strength of their candidates or platform, Republicans have gerrymandering to thank once more for their renewed House majority. After the 2010 census, responsibility for congressional redistricting fell largely to Republican-controlled state legislatures, which clumped voters in districts that would help more from the party get elected.
What remains is a House remarkably insulated from national electoral swings — a contrast with the founding fathers’ image of a chamber more susceptible to the will of the people, said Michael Li, an expert on redistricting and senior counsel for the Brennan Center for Justice’s Democracy Program.
There were concerns that anything but a Trump victory could present new obstacles for Speaker Paul D. Ryan. During the campaign, many conservative members who backed Mr. Trump expressed frustration with Mr. Ryan, the highest-ranking Republican elected official, for declining to defend Mr. Trump after the release of that 2005 recording.
That frustration has metastasized into mutinous murmurings about blocking Mr. Ryan’s re-election as speaker. Before Election Day, at least a handful of Republicans had declined to say if they will back him in internal leadership elections, scheduled to be held when Congress returns early next week.
But Mr. Trump’s victory is likely to pose its own problems for Mr. Ryan, who became more vocal in his support for his party’s presidential candidate in the final days before the election, mentioning Mr. Trump by name as he urged Americans to vote Republican, up and down the ticket. Though he spoke of reconciliation and unity in his victory speech early Wednesday morning, Mr. Trump is known for his almost uncontrollable need to retaliate for even perceived slights, a fact that could come back to haunt Mr. Ryan.
As the race appeared to be turning in Mr. Trump’s favor, Mr. Ryan gave brief remarks at his own victory party Tuesday evening. He did not mention the man who would soon be president-elect but alluded to the potential for an expectation-defying election for his party.
“This could be a good night for us,” Mr. Ryan said.