The deep divisions that have defined American politics in the era of President Trump played out across the country in Tuesday’s midterm elections, as Democrats scored victories in key races in Republican-held suburban House districts but ran into a wall of opposition in red-state Senate contests.

All year long, Democrats talked optimistically about a blue wave that they believed was building around the country, one powerful enough to flip control of the House and even, against the odds, put the Senate in play as well. But a somewhat different reality began to set in early in the evening as the familiar contours of red and blue America powerfully reasserted themselves.

A change in the balance of power in the House would represent a pulling back from the president by key parts of the electorate, particularly by female voters. That alone could have a significant effect on the second half of Trump’s first term, particularly in Washington.

But the overall voting patterns in House, Senate and gubernatorial contests signaled that the differences and divisions that have defined the country during Trump’s presidency remain and seemingly are growing stronger. That sets the stage for a contentious and competitive presidential election two years from now, with the stakes now higher than ever.

Trump quickly claimed credit for the Republican successes in key Senate races, after campaigning almost nonstop over the last weeks of the midterms, focusing heavily on states where he had done best in his 2016 victory.

By elevating the issue of immigration with warnings, without evidence, of a coming invasion of undocumented immigrants, Trump again put the Democrats on the defensive and found a way to protect the GOP’s narrow majority in the Senate. But those same tactics may have contributed to the success of Democrats in some of the most contested House races.

Republican Governor-elect Ron DeSantis triumphed over Democrat Andrew Gillum in Florida in a hard-fought election that brought Gillum national prominence. (Jenny Starrs/The Washington Post)

Some House races, including those in California where Democrats hoped to pick up seats, remained to be counted, and Democrats fell short in some districts they had hoped to win. But overall, they did what they set out to do, which was to find a way to put a check on the president and a Republican Party that had held all the levers of power in Washington since 2016.

For Democrats, the elation they felt over the prospect of capturing the majority in the House was tempered by what happened to their candidates in some of the highest profile statewide races.

In Florida, Democrat Andrew Gillum, whose progressive agenda had excited many in the Democratic base, fell narrowly to Republican Ron DeSantis, who as much as any candidate in the country had wrapped himself in the mantle of Trump.

In Texas, Rep. Beto O’Rourke, who attracted a national following among Democrats and raised tens of millions of dollars from all over the country, lost to Republican Sen. Ted Cruz.

In Georgia, Democrat Stacey Abrams, bidding to become the first African American woman to lead a state, was trailing Republican Brian Kemp in a race that had turned ugly toward the close.

Democrats suffered a double disappointment in two key presidential battlegrounds, losing governor's races in both in Florida and Ohio, where Republican Mike DeWine defeated Democrat Richard Cordray.

Those losses were a reminder to Democrats that the electoral map remains challenging even if they hold an advantage in the overall popular vote in the country.

Those issues await an election two years away, but what happened Tuesday will be very much on the minds of the president’s strategists and those who will be working for the many Democrats now thinking of seeking their party’s nomination. They all will have to contend with what Tuesday’s voting said about the country as a whole.

This was an election that once again saw men and women moving in different directions. In key suburban districts, Democratic challengers were counting on the support of women, particularly women with college degrees, to push them over the top. But there were signs that white men, especially those without college degrees, who have become the backbone of the Trump coalition, also were coming out in significant numbers.

A Washington Post-Schar School poll found that women in battleground House districts were 12 points more supportive of Democratic candidates than Republican candidates, and white women with college degrees backed Democratic candidates more than 20 percentage points more than they backed Republican candidates. White men with college degrees, by way of contrast, supported Republican candidates by 12 points.

Republicans had suffered from an intensity gap earlier in this election cycle, but a combination of factors helped to narrow the Democrats’ advantage. In part, the normal patterns of partisans coming home as Election Day neared took hold. But the confirmation battle over Supreme Court Justice Brett M. Kavanaugh, which turned into a bitter fight, helped to energize the GOP coalition as well. Added to that was Trump’s relentless campaigning.

The Post-Schar School survey underscored the degree to which these midterm elections, perhaps more than any in the recent past, had raised the emotional level of the population. Nearly four in 10 voters (35 percent) in battleground districts said one principal word they would use to describe their feelings about this election was “angry.” Another 37 percent called themselves “anxious.”

Perhaps reflecting the exhaustion of a time in which everything seems hyperpartisan and supercharged, 42 percent said they were hopeful about what the election results would bring. Network exit polls, meanwhile, found that nearly eight in 10 Americans said they believed the country was more divided than ever.

With Democrats gaining control of the House, both Democratic congressional leaders and the president will face some difficult choices in the months ahead. The president will have to decide whether to try to work with Democrats. Congressional Democrats will have to make a similar calculation.

Democrats have pledged to move forward on an agenda that includes political change, health care and infrastructure. They and Trump could find agreement on infrastructure and possibly on drug prices. The two sides also will have to reach agreement on a budget and an extension of the debt ceiling. The new trade agreement with Canada and Mexico will consume time during the first half of 2019, too.

But the bigger question that will define the coming year or more is what Democrats decide to do about investigating the president and his administration. Looming over that is the pending report from special counsel Robert S. Mueller III, who is leading the investigation into Russia’s role in the 2016 election and possible collusion with people associated with the Trump campaign.

What the Democrats do on the question of investigation will shape the relationship, such as it is, between Democrats in Congress and the president. What isn’t likely to change is how the country as a whole views those battles.

The House takeover represents a significant change in the status quo in Washington. But it might end up doing little to affect the overall shape of an America deeply divided over the leadership of the president.