Democrats gained control of the U.S. House on Tuesday night, winning a foothold on power in an election that served as a national referendum on President Trump and a test of the support that powered him to the White House.

But it wasn't the definitive wave that some had hoped for. Even as Democrats looked to add at least two dozen House seats, Republicans were on track to expand their majority in the Senate. In the end, one of the most emotionally charged midterm elections in years again showed a country deeply divided by demographics and geography.

In the House, unofficial returns showed suburban voters in educated, affluent areas delivering a sharp rebuke to Trump and the GOP — including in districts outside Philadelphia, Chicago, and Washington. Republican Senate candidates ran strong in more conservative, rural states such as North Dakota, Indiana, and Tennessee.

The results continued a realignment that began before Trump, but has accelerated under his tumultuous presidency.

"There is an instability in the electorate right now that is really breathtaking, and there are deepening political divisions that I think basically provide an open keg of gunpowder that's at risk of being set off," said Phil English, a former Republican congressman from Erie County.

Aided by new congressional maps and Republican retirements, Democrats won several key House races in Pennsylvania, adding seats in Chester and Delaware Counties and the Lehigh Valley — but fell short in other places, including in Bucks County, where Republican Rep. Brian Fitzpatrick held on in one of the country's most watched contests.

New Jersey Democrats were expected to gain at least three House seats — and a fourth Republican district anchored in Burlington and Ocean Counties was too close to call as of midnight.

A House controlled by Democrats would be a seismic shift in the political landscape and Trump's presidency. It could severely constrain the president's ability to advance major legislation and will likely subject his administration to congressional subpoenas and investigations that could command headlines and resources.

"Tomorrow will be a new day in America," Nancy Pelosi, the Democratic House leader, said at a victory party.

At least three Pennsylvania women were poised to join what had been the state's all-male congressional delegation — symbolizing how suburban women have become leading voices of the backlash to Trump, capturing outrage and newfound activism after his victory.

Mary Gay Scanlon hugs a supporter at her election watch party at the Inn at Swarthmore on Tuesday.
YONG KIM / Staff Photographer
Mary Gay Scanlon hugs a supporter at her election watch party at the Inn at Swarthmore on Tuesday.

"This is something I've never seen in my community," said Chrissy Houlahan, a Chester County Democrat driven by the 2016 results who won a House seat in her first campaign for public office. "I have never seen the kind of energy we have right now in our community. Thanks to you, we are making history tonight."

At the same time, Republicans' expansion in the Senate will enable them to bottle up Democratic bills and continue confirming federal judges, allowing Trump to reinforce a conservative imprint on the judiciary.

As the results came into focus, the president tweeted: "Tremendous success tonight. Thank you to all!"

Critical Senate races unfolded in some of the most Republican-friendly states in the country, helping the GOP unseat several Democrats. Some Democrats took heart in the fact that they didn't lose more ground, considering 10 of their incumbents were running in states Trump won.

Democrats did score victories in Rust Belt and Midwestern states such as Michigan and Ohio that had handed the president vital victories two years ago. In Pennsylvania, Gov. Wolf and Sen. Bob Casey were both projected as winners minutes after the polls closed, each defeating Republican challengers who had attempted to re-create Trump's appeal in the state. Democrats won the governor's office in Kansas as well.

Sen. Sherrod Brown (D., Ohio) cast his reelection as a road map to challenging Trump on his own turf in 2020.

"You showed the country that progressives can win – and win decisively – in the heartland," he said after coasting to victory. "Populists are not racists. Populists are not anti-Semitic."

But Republicans following Trump's playbook won hotly contested gubernatorial races in Florida and Georgia.

"You can't have a wave election when both sides are energized," former Pennsylvania Sen. Rick Santorum, a Republican, said on CNN.

The election was the first national measure since Trump's stunning 2016 election, one that many Democrats hoped would deliver a rejoinder after two years of political turmoil.

They cast the race as a contest over honesty, dignity, and the character of the country.

"For two years, people have been banging their head against the wall wondering how the Republicans were getting away with the lies, the racism, and the corruption," tweeted Dan Pfeiffer, a former White House aide under Barack Obama and cohost of the liberal podcast Pod Save America. "Today is the day that we can finally hold them accountable for their behavior."

To Trump and his supporters, it was a chance to show that his backing runs far deeper than polls or political insiders believe — and remains strong ahead of his 2020 reelection bid.

"Everything we have achieved is at stake," Trump told supporters in Indiana on Monday.

Roughly 70 percent of likely voters hoped their vote would send Trump a message of either support (28 percent) or opposition (42 percent), according to a CNN poll released on the eve of the election. In much of the Philadelphia region, election officials reported long lines and vote totals that far exceeded the typical midterm election, despite rain.

"I voted angry," said Sam Brackeen, a 72-year-old retiree from Montgomery County. He said he doesn't always vote for a straight Democratic ticket — but did so Tuesday. "I feel like I am part of a wave of people who are sending [President Trump] a message. 'We're not going to put up with this foolishness.' "

Anger, hopefulness, and anxiety were the most common moods voters described to a Washington Post-Schar School poll conducted Monday and Tuesday.

In Manayunk, Diane Colucci, 69, said she would "like to see people back down and give [Trump] a chance, maybe." 

Americans went to the polls less than two weeks after one man attempted to mail pipe bombs to Trump critics and the news media and after another man, railing against immigrants, killed 11 people at a Pittsburgh synagogue.

Despite those incidents, and a strong economy that might have served as the backbone of a different approach, Trump locked in on immigration for the final weeks of the campaign. He fanned fears of migrants walking toward the U.S. border, but still hundreds of miles away, in an effort to rouse his supporters and return to the themes that underpinned his 2016 campaign.

The strategy seemed aimed at rallying Trump supporters in red-state Senate races, but it also put the spotlight back on the  racially charged approach that has driven opposition to his presidency, particularly in the suburban areas with the most competitive House races.

"The negativity toward people, and having it on display, is horrific, and the person who is supposed to be our leader is the name-caller," said Shamelle Smith, 48, of Maple Shade.

Two-thirds of Pennsylvania voters said the president was a factor in their vote, according to an Associated Press VoteCast survey. Nearly 6 in 10 thought the country was on the wrong track, even though two-thirds gave the economy high marks.

History and political geography suggested that Democrats had the upper hand in the House — the president's party almost always loses ground in midterm elections. The Senate map provided a different playing field.

The two contrasting parts of America produced starkly different results.

Staff writers Stacey Burling, Jan Hefler, and Justine McDaniel contributed to this article.