Democrats rode a wave of dissatisfaction with President Donald Trump to win control of the US House of Representatives, giving them the opportunity to block Trump's agenda and open his administration to intense scrutiny.
In midterm elections held two years after he won the White House, Mr Trump and his fellow Republicans expanded their majority in the US Senate following a divisive campaign marked by fierce clashes over race, immigration and other cultural issues.
But today's results were a bitter outcome for Trump after a campaign that became a referendum on his leadership.
NBC News projected Democrats would hold a 229-206 House majority, taking over control from the Republicans for the first time in eight years. Other media outlets also projected that the Democrats would pick up at least the 23 Republican-held seats they needed to win to gain a majority.
With a House majority, Democrats will have the power to investigate Trump's tax returns, possible business conflicts of interest and allegations involving his 2016 campaign's links to Russia.
They also could force Trump to scale back his legislative ambitions, possibly dooming his promises to fund a border wall with Mexico, pass a second major tax-cut package or carry out his hardline policies on trade.
A simple House majority would be enough to impeach Trump if evidence surfaces that he obstructed justice or that his 2016 campaign colluded with Russia. But Congress could not remove him from office without a conviction by a two-thirds majority in the Republican-controlled Senate.
Democrats in the House could be banking on launching an investigation using the results of US Special Counsel Robert Mueller's already 18-month-old probe of allegations of Russian interference on Trump's behalf in the 2016 presidential election. Moscow denies meddling and Trump denies any collusion.
"Thanks to you, tomorrow will be a new day in America," Democratic House leader Nancy Pelosi told cheering Democrats at a Washington victory party, saying House Democrats would be a check on Trump.
"The American people want peace, they want results," Pelosi added.
Despite his party losing the House, Trump wrote on Twitter, "Tremendous success tonight."
Trump - a 72-year-old former reality TV star and businessman-turned-politician - hardened his rhetoric down the stretch on issues that appealed to his conservative core supporters, issuing warnings about a caravan of Latin American migrants headed to the border with Mexico and condemnations of liberal American "mobs."
Most Democratic candidates in tight races stayed away from harsh criticism of Trump during the campaign's final stretch, focusing instead on bread-and-butter issues like maintaining insurance protections for people with pre-existing medical conditions and safeguarding the Social Security retirement and Medicare healthcare programs for senior citizens.
Democrats also captured governorships in Michigan, Illinois and Kansas. In Kansas, Republican Kris Kobach, a Trump ally who was a leader of the president's disbanded voter fraud commission, fell to Democratic state senator Laura Kelly.
Democrats turned out in droves
Democrats turned out in droves to register disapproval of Trump's divisive rhetoric and policies on such issues as immigration and his travel ban targeting several Muslim-majority countries.
A record number of women ran for office this election, many of them Democrats turned off by Trump's policy agenda.
The election results mean Democrats will resume House control in January for the first time since the 2010 election, beginning a split-power arrangement with the Republican-led Senate that may force Trump to scale back his legislative ambitions and focus on issues with bipartisan support, such as an infrastructure improvement package or protections against prescription drug price increases.
It also will test Trump's ability to compromise, something he has shown little interest in over the last two years with Republicans controlling both chambers of Congress.
The loss of power will test Trump's political hold on House Republicans, most of whom had pledged their support for him lest they face the wrath of the party's core supporters, who remain in his corner.
The final weeks before the election were marked by the mailing of pipe bombs to his top political rivals, with a political fan of Trump arrested and charged, and the mass shooting at a Pittsburgh synagogue in which 11 people died, sparking a debate about Trump's biting rhetoric and whether it encouraged extremists.
In the House, Democrats picked up seats across the map, ousting incumbent Republican Barbara Comstock in suburban Virginia and sending Donna Shalala, a former Cabinet secretary under President Bill Clinton, to the House in south Florida.
In the Senate, where Democrats were defending seats in 10 states that Trump won, Republicans ousted three Democratic incumbents.
Republican Mike Braun captured incumbent Joe Donnelly's seat in Indiana, Republican Kevin Cramer beat incumbent Democratic Senator Heidi Heitkamp in North Dakota and Republican Josh Hawley defeated Democrat Claire McCaskill in Missouri.
Some of the biggest Democratic stars of the campaign lost. Liberal House member Beto O'Rourke became a national sensation with his underdog U.S. Senate campaign but fell short in conservative Texas to Senator Ted Cruz, and Andrew Gillum lost to Republican Ron DeSantis in his quest to become the first African-American governor of the key swing state of Florida.
Incumbent Democratic Senator Joe Manchin won a hotly contested race in conservative West Virginia, and conservative Marsha Blackburn held a Senate seat for Republicans.
Senators Bernie Sanders of Vermont, a 2016 Democratic presidential contender, and Tim Kaine of Virginia, Hillary Clinton's vice presidential nominee in 2016, easily won re-election. Democratic Senator Sherrod Brown held his seat in Ohio.
All 435 seats in the House, 35 seats in the 100-member Senate and 36 of the 50 state governorships were up for grabs.
Investors often favor Washington gridlock because it preserves the status quo and reduces uncertainty, even though many investors this time around had been hoping for a continuation of the Republican agenda.
A Reuters analysis of the past half century showed stocks fared better in the two calendar years after congressional elections when Republicans control Congress and the presidency than when Democrats controlled the two branches, and at least as well as during times of gridlock.
"I think everyone was bracing for any possible, crazy scenario to show itself tonight but it basically looks like the baseline consensus forecast was correct," said Michael Purves, Head Of Equity Derivatives Strategy At Weeden & Co, New York. "If the futures are up now and they stay up it's because there is an uncertainty factor that is now out of the market."