A Democrat has pulled ahead for the first time in late vote counting in California's 21st Congressional District and if that lead holds, Democrats would appear to be on track to gain an even 40 seats in the House of Representatives after the 2018 midterm elections.

After trailing by about 5,000 votes – more than 7 percentage points – on election night, Democrat TJ Cox leads Republican incumbent Rep. David Valadao by 436 votes after an update Monday night to the running count.

Valadao had declared victory on Election Day and The Associated Press had called the race in his favor, but Cox continued to chip away at Valadao's lead as the count continued. The AP retracted its race call Monday in light of the new vote total.

The race could flip again with thousands of votes left to count in the counties that fall in California's 21st District, which includes the San Joaquin Valley. But an analysis by The Fresno Bee found that if the current margins in those counties hold, Cox would likely hold on to win by a tiny margin.

"Here in the Central Valley, we are often underestimated and counted out," Cox said in a statement after he took the lead. "But while the national spotlight focused elsewhere, our hard-working communities came together to fight for better health care, good jobs, and more opportunities."

Trump's proclamation comes true:Rep. Mia Love loses re-election bid in Utah

More:Mia Love slams Trump, says GOP paid price for not letting minorities 'into their hearts'

"We still knew we had a path to victory and every vote update just reconfirmed that," Cox campaign spokesman Phillip Vander Klay told USA TODAY when asked about coming back from a large Election Day deficit.

Cox is an engineer and small businessman. His campaign to unseat the three-term incumbent Valadao focused on health care and voters' concerns about President Donald Trump's immigration policies, Vander Klay said.

The Valadao campaign did not immediately respond to USA TODAY's request for comment.

Democrats have already flipped six Republican-held seats in California, including four in Orange County, which had previously been considered a Republican stronghold in the largely blue state.

A Cox win would put Democrats on track to gain 40 seats in the House. Two races in New York had remained uncalled heading into this week, but Democrat Nate McMurray conceded the race in New York's 27th Congressional District to Republican Rep. Chris Collins on Monday.

The race in New York's 22nd Congressional District has Democratic candidate Anthony Brindisi ahead of Republican Rep. Claudia Tenney by more than 4,000 votes. Local election officials said they expect to complete their count of absentee ballots this week.

Tenney has not conceded, but said last week that a win for her appears unlikely.

Contributing: The Associated Press

More:Democrat Mike Espy walks fine line on issue of race in Mississippi Senate contest

More:Will Beto run for president in 2020? He's not saying 'no' at El Paso town hall