In the early hours of election night on Tuesday, a consensus began to take hold that the vaunted Democratic blue wave that had been talked about all year was failing to materialize. Now, with a handful of races still to be called, it’s clear that an anti-President Trump force hit the country with considerable, if uneven, strength.

Democrats appear poised to pick up between 35 and 40 seats in the House, once the last races are tallied, according to strategists in both parties. That would represent the biggest Democratic gain in the House since the post-Watergate election of 1974, when the party picked up 49 seats three months after Richard M. Nixon resigned the presidency.

Republicans will gain seats in the Senate, but with races in Florida and Arizona still to be called, their pre-election majority of 51 seats will end up as low as 52 or as high as 54. Meanwhile, Democrats gained seven governorships, recouping in part losses sustained in 2010 and 2014, and picked up hundreds of state legislative seats, where they had suffered a virtual wipeout in the previous two midterm elections.

The Democrats’ gains this week are still far short of what Republicans accomplished in their historic victories of 1994 and 2010. But they would eclipse the number of seats Democrats gained in 2006, the last time the party recaptured control of the House, as well as the 26-seat gain in 1982, when the national unemployment rate was at 10 percent. This year, the election took place with the unemployment rate at just 3.7 percent.

Day by day, the outlook for Democrats in the House has improved. At the offices of the Democratic Congressional Campaign Committee, already high spirits have been rising all week as more races fell into the party’s column. One joke that has been making the rounds there goes like this: “This is actually turning out to be more of a Hanukkah than a Christmas election,” meaning day after day of gifts, rather than just one.

This was always an election that would test the strength of the economy, which favored the president’s party, vs. the president’s low approval ratings, which, along with the record of past midterm elections, pointed to Democratic gains. In the end, history and presidential approval combined to give Democrats control of the House by what appears to be a comfortable margin.

The Democratic wave hit hardest in suburban districts, many of them traditional Republican territory, where college-educated voters — particularly women — dissatisfied with the president backed Democratic challengers. Ronald Brownstein of the Atlantic and CNN, who has closely tracked these changes over many elections, noted in a post-election article that, before the election, two-thirds of Republicans represented congressional districts where the percentage of the population with college degrees was below the national average. After the election, he estimated, more than three-quarters of GOP House members now will represent such districts.

Democrats flipped about two-thirds of the competitive districts won by both Hillary Clinton in 2016 and Barack Obama in 2012 or by Clinton in 2016 and Mitt Romney in 2012. They also picked up one-third of districts won by Trump in 2016 and Obama in 2012. In districts where both Trump and Romney had won in the previous two elections, Democrats gained about a quarter of the competitive seats.

Also striking in House races was the number of narrow victory margins — on both sides. About 20 Democrats won or are leading in races where the margin is fewer than five percentage points, while about two dozen Republicans who won or are leading are in races with similarly small margins.

That indicates that the outcome in 2018 could have been substantially better for Democrats or significantly worse, had the political winds been blowing differently. It also foreshadows another fiercely contested election for the House in 2020.

The final outcome in the Senate races this year will also have a bearing on 2020. The difference between a majority of 54 seats or 52 seats would have a sizable impact on the odds of Democrats being able to win control two years from now.

Republicans expect to defend 22 seats up for election, compared with only 12 seats held by Democrats. These include the Colorado seat of Sen. Cory Gardner (R), the Maine seat of Sen. Susan Collins (R) and the Arizona seat now held by Sen. Jon Kyl (R). Senate Republicans Joni Ernst of Iowa and Thom Tillis of North Carolina are likely to face competitive races. Democrat Doug Jones of Alabama, who won a special election last year, also will face a serious challenge to hold his seat.

Beyond the tally of victories and defeats, the 2018 election was notable for the ways in which it deepened many of the divisions and shifts in allegiance that are changing the political landscape across the country. That carries implications for politics in 2020 and beyond.

Democratic strategists have been cheered by exit polls that show the underlying national demographic trends that drove their gains, particularly in the border states of California, Arizona, New Mexico and Texas.

Voters under the age of 29 voted for Democrats over Republicans by 67 percent to 32 percent, a margin which beats the previous record in the 2008 presidential election. Latino voters matched their national 11 percent vote share from the higher-turnout 2016 election, with Democrats winning 69 percent of the Latino vote nationwide, slightly more than the 66 percent share when Trump was elected. Asian voters, who make up about 3 percent of the voting population, sided with Democrats by a margin of 77 percent to 23 percent.

“The emerging electorate, the one which will dominate U.S. politics for the next generation or two, supported Democrats in record numbers,” said Simon Rosenberg, a Democratic strategist. “Democrats not only won the 2018 election handily, but won it in a way which should worry Republicans about 2020.”

Said Republican pollster Whit Ayres: “To me, the big story is that the 2018 midterm election reinforced and accelerated the patterns we saw in 2016. You had smaller, overwhelmingly white, rural counties become more deeply entrenched in the Republican Party, and suburban counties, particularly those with high proportions of well-educated voters, going exactly the opposite direction.”

New returns have been raising Republican concerns in western states. Chuck Coughlin, a Republican adviser to former Arizona governor Jan Brewer (R), said it was clear that Trump’s approach to immigration in the final weeks of the campaign did not have the nuance required for a state like Arizona, where immigrants play a central role in the economy.

“One thing is for certain, that the caravan rhetoric doesn’t resonate in this state as well as it resonates in the Midwest,” Coughlin said. “We have done a lot of research, and we have consistently shown that border security is a big issue, but the immigration reform side of that question is integral to the future of the state.”

Republicans in the state, however, have been hemmed in by Trump’s support among Republican primary voters, which forced Rep. Martha McSally, the Republican nominee for Senate, to tack to the right, particularly on immigration. “She didn’t ever modulate,” said Coughlin. “She didn’t create any separation.” Rep. Kyrsten Sinema, the Democratic Senate nominee, now has a narrow lead in that race.

In neighboring Colorado, Democrats won every statewide race, picked up a House seat, took control of the state Senate, and swept most down-ballot races as well. “We are not Ohio, Michigan or the Midwest. The college-educated suburban voter — they don’t like Trump because of his behavior,” said Dick Wadhams, the former chairman of the state GOP.

In Nevada, Democrats picked up a Senate seat and the governorship and held on to two competitive House districts, in a sign of a continued shift left in what has been a closely contested state in most recent elections.

Democrats fell short in two other evolving Sun Belt states. In Texas, Democratic Rep. Beto O’Rouke lost the Senate race to incumbent Sen. Ted Cruz but managed to win 48 percent of the vote. Meanwhile, Democrats picked up two suburban congressional districts.

In Georgia, Democrat Stacey Abrams trails Republican Brian Kemp in the gubernatorial race, but the changing dynamics of voting patterns there worry some Republicans for future elections.

“When you have someone like Stacey Abrams carrying a major Atlanta suburban county like Gwinnett, like Hillary Clinton did, then the formula for Republican victories in Georgia has been completely upended,” Ayres said.

Other results point in a different direction, however, which offers some encouragement to Republicans beyond adding to their narrow Senate majority.

Ohio appears to be moving steadily away from the Democrats, largely because of cultural issues. Since 1994, Republicans have won nearly nine of every 10 statewide contests. The GOP’s victory in the open gubernatorial race on Tuesday was the latest blow for the Democrats, though Democratic Sen. Sherrod Brown held his seat.

Democrats also failed to pick up the governorship in Iowa, though they gained two House seats. They struggled to make inroads in House races in Republican strongholds such as Kentucky, North Carolina and Nebraska.

Florida remains a top concern heading into the 2020 elections, when the state will probably play a crucial role in any path for Trump to win a second term. Contrary to the Latino vote elsewhere in the country, the Cuban, Puerto Rican and Central American populations in the Sunshine State split more evenly, as Gov. Rick Scott (R) mounted an aggressive outreach effort.

“The Democrats underestimated just how much Hispanic support Republicans were able to capitalize on in Florida,” said Fernand Amandi, a Democratic pollster in Miami. “It’s about the margins.”

Of the 15 percent of voters in the state who were Latino, Scott was able to win 45 percent, according to exit polls, including a slight majority of Latino men. The Republican gubernatorial candidate, former congressman Ron DeSantis, was able to win 44 percent of Latino voters.