Democrats were expected to take control of the House while Republicans held their Senate majority in a historic midterm election Tuesday that shaped up as a pivotal referendum on President Donald Trump and the leadership of the GOP.

Pushing the Democrats closer to their House victory were Lauren Underwood and Sean Casten of Illinois, who unseated incumbent Republican Congressmen Randy Hultgren and Peter Roskam, respectively.

The national outcome carried serious consequences for the president and could also have implications for Democrats in the 2020 presidential election. Sens. Bernie Sanders and Elizabeth Warren held their seats. Rep. Beto O’Rourke, a progressive darling, mounted a strong challenge to GOP Sen. Ted Cruz in Texas but came up short.

Democrats also went into Tuesday’s vote with history on their side. The party in power traditionally struggles in midterm elections, and Republicans found themselves playing defense in House races around the country.

In Illinois’ 6th District, Roskam lost to Casten, who had 53 percent of the vote with 77 percent precincts reporting. In the 14th District, Hultgren lost to Underwood, who had 51.7 percent of the vote with 96 percent of the precincts reporting.

That win made Underwood the first black politician to represent the district.

“We must be a beacon of hope, we must lead by example, we are a democracy and we demand better,” Underwood told supporters. “The 116th session of the United States Congress will convene on Jan. 3, 2019, and we’re still waiting on news around the country but I feel confident I’m going to have a lot of great women to work alongside. You’ve heard me talk about the girlfriends around the country, and the girlfriends are winning.”

Democrat Jesus “Chuy” Garcia won the race to fill the vacated seat of his political ally, Rep. Luis Gutierrez. Garcia had 86.5 percent of the vote with 98 percent of the  precincts reporting. The Republican, Mark Lorch, had 13.5 percent.

Meanwhile, Rep. Dan Lipinski handily won re-election in the 3rd District with 73.7 percent of the vote  and 95 percent of precincts reporting. His Republican challenger there, Arthur Jones, is a Holocaust-denier who got more than 26 percent of the ballots cast — or more than 55,000 votes.

Nationally, the midterm campaign unfolded against a backdrop of jarring political imagery, heated rhetoric and angry debates on immigration, health care and the role of Congress in overseeing the president.

Democrats, whose very relevance in the Trump era depended on winning at least one chamber of Congress, were laser-focused on health care as they predicted victories that would break up the GOP’s monopoly in Washington and state governments.

The political and practical stakes were sky-high.

Democrats could derail Trump’s legislative agenda for the next two years should they win control of the House. And they would claim subpoena power to investigate Trump’s personal and professional shortcomings.

Some Democrats have already vowed to force the release of his tax returns. Others have pledged to pursue impeachment, although removal from office is unlikely since the GOP controls the Senate.

Trump’s party will maintain Senate control for the next two years, at least. The president had encouraged voters to view the first nationwide election of his presidency as a referendum on his leadership, pointing proudly to the surging economy at recent rallies.

Trump’s team immediately sought to give him credit for retaining their narrow Senate majority, even as  Republicans lost the House.

“It’s a huge moment and victory for the president,” Press Secretary Sarah Huckabee Sanders told reporters at the White House Tuesday night.

Trump himself tweeted “Tremendous success tonight. Thank you to all!”

Tuesday’s elections tested the strength of a Trump-era political realignment defined by evolving divisions among voters by race, gender, and especially education.

The president’s Republican coalition is increasingly older, whiter, more male and less likely to have a college degree. Democrats are relying more upon women, people of color, young people and college graduates.

Women voted considerably more in favor of their congressional Democratic candidate — with fewer than 4 in 10 voting for the Republican, according to VoteCast, a nationwide survey of more than 113,000 voters and about 20,000 nonvoters — conducted for The Associated Press by NORC at the University of Chicago.

All 435 seats in the U.S. House were up for re-election Tuesday, although fewer than 90 were considered competitive. Some 35 Senate seats were in play, as were almost 40 governorships and the balance of power in virtually every state legislature.

Contributing: Lauren FitzPatrick, Sam Charles, Associated Press