US President Donald Trump has hailed "tremendous success" in the mid-term elections after a night of mixed results for his Republican party.
The Democrats won the House of Representatives, which will enable them to thwart the president's agenda.
But the Republicans consolidated their grip on the Senate, ensuring he can still make key appointments.
Mr Trump said the outcome "defied history" as the ruling party does not usually gain seats in the mid-terms.
At a feisty news conference on Wednesday, Mr Trump offered an olive branch to Democrats, proposing both parties work together on joint legislative priorities.
But he said that if Democratic-controlled congressional committees started serving legal writs against his administration, Republicans would do likewise and gridlock would ensue.
In ill-tempered exchanges, Mr Trump called a CNN correspondent "a rude, terrible person" and told an NBC reporter: "I'm not a big fan of yours either."
He told a black reporter who asked whether his self-professed nationalism would embolden white nationalists that it was "such a racist question".
The president also mocked Republicans who did not "embrace" him on the campaign trail, and went on to lose their election races.
"They did very poorly," Mr Trump told reporters. "I'm not sure that I should be happy or sad but I feel just fine about it."
House Democratic leader Nancy Pelosi has promised her party will serve as a counterweight to the White House.
Ms Pelosi - who is favourite to become speaker, a position she held from 2007-11 - told supporters: "Today is more than about Democrats and Republicans. It's about restoring the Constitution's checks and balances to the Trump administration."
Meanwhile the Florida Senate race is heading for a recount after Republican Rick Scott got 50.21% and incumbent Bill Nelson 49.79% of the vote. A margin of less than half a percentage point automatically triggers a recount.
What difference will the new Congress make?
The Democrats gained more than the 23 seats they needed for a majority in the 435-seat lower chamber.
They could now launch investigations into Mr Trump's administration and business affairs, from tax returns to potential conflicts of interest.
The Democrats could also more effectively block his legislative plans, notably his signature promise to build a wall along the border with Mexico.
In the Senate, Democrats were facing an uphill battle because they were defending 26 races, while just nine Republican seats were up for grabs.
The Republicans are on course to increase their representation from 51 to 54 in the 100-seat Senate upper chamber.
Mr Trump has threatened to retaliate for any Democratic investigations with his own probes in the Senate into alleged "leaks of classified information".
If the Democrats think they are going to waste Taxpayer Money investigating us at the House level, then we will likewise be forced to consider investigating them for all of the leaks of Classified Information, and much else, at the Senate level. Two can play that game!— Donald J. Trump (@realDonaldTrump) November 7, 2018
By Anthony Zurcher, BBC News, Washington
Even handing over power to Democrats in the House may have a bit of a silver lining for the president.
Now he will have someone to blame if the economy takes a turn for the worse (and, given business cycle realities, it might). He's got a ready-made explanation for why he can't get anything done in the next two years - and a pitch for what needs to change in the next election.
Day in and day out, he'll have a set of clear political opponents to contrast himself with.
Both Bill Clinton and Barack Obama lost control of the House in their first term in office and went on to win re-election. History, serving as a guide, predicted this would probably be a bad night for the president.
History also indicates that while the road may be rocky, better days could be ahead.
More on the mid-terms:
Who are the new faces in Congress?
Female candidates fared particularly well in an election cycle that had been billed as the Year of the Woman.
Two 29-year-old Democrats - Alexandria Ocasio-Cortez and Abby Finkenauer - are due to be the youngest women ever to win House seats.
Ilhan Omar and Rashida Tlaib are the first Muslim women and Sharice Davids and Debra Haaland the first Native American women to be elected to Congress. All are Democrats.
Ayanna Pressley was elected as Massachusetts' first black congresswoman.
What's happening in governors' races?
Governors - who head the executive branch in state governments - have been chosen in 36 out of 50 states.
In Florida, a progressive Democrat conceded after an ugly battle against Trumpist conservative Ron DeSantis.
But in Georgia, Democrat Stacey Abrams - who was hoping to become the first black female governor in the US - refused to concede as her Republican opponent Brian Kemp took a commanding lead after a bitter campaign.
Democrats also captured governorships in Michigan, Illinois, Kansas and Wisconsin, where former Republican presidential contender Scott Walker was beaten.
New York Democratic Governor Andrew Cuomo - sometimes spoken of as a 2020 presidential contender - cruised to a third term.