Democrats have gained 40 House seats, as NBC News on Thursday declared TJ Cox the apparent winner in California's 21 District.

Incumbent Republican Rep. David Valadao conceded on Thursday afternoon, following weeks of ballot counting in the tight race. With 100 percent of ballots tallied, Cox had 50.4 percent of the vote; Valadao trailed by 862 votes, according to NBC News.

Cox declared victory on Nov. 28, when he lead by more than 500 votes.

NBC had called the race for Valadao, but retracted that call as the count tightened after Election Day.

The gain brings House Democrats' total seats to 235, with Republicans occupying 199 seats, according to NBC.

The California seat was an early target for the Democratic Congressional Campaign committee; Hillary Clinton won the southern-central California district by more than 15 points in 2016.

On Thursday, NBC also withdrew its call in North Carolina's 9th Congressional District. The race had initially been called for Republican Mark Harris, but on Thursday Democrat Dan McCready withdrew his concession amid allegations of vote fraud and the possibility that a new election will be held.

Meanwhile, Democrats have won the House with the largest margin of victory in a midterms election for either party, according to NBC News election data.

The Democrats' national margin of victory in House contests smashed the previous midterms record of 8.7 million votes in 1974, won just months after President Richard Nixon resigned from office in disgrace amid the Watergate scandal.

This year, Democrats topped Republicans by 9.5 million votes, winning 53.4 percent of votes cast compared to 44.9 percent for the GOP.