The wealthiest member of Congress is keeping his job.

Republican Darrell Issa narrowly defeated Marine-turned-lawyer Doug Applegate after a bitter contest in in the 49th District north of San Diego.

Unofficial returns Monday showed Issa holding a 2,348-vote edge, with only a small number of votes left to tally. Vote-counting extended for weeks after the election as officials tallied late-arriving mail ballots and those filled out at polling places.

For years, the eight-term congressman and chief antagonist of President Barack Obama and Democrat Hillary Clinton faced scant competition in the Republican-leaning district. But Donald Trump's presence on the top of the ticket and diversifying electorate opened the way for a tight contest.

"I am eager to continue working to advance the best interests of the American people and restoring the focus of Washington where it belongs: Economic prosperity, national security and government accountability," Issa said in a statement. "With our newly unified government, we have the opportunity to lead the country in a new and better direction."

Republicans are on track to hold at least 240 seats in the House next year. With Issa keeping his seat, the only unresolved races left in the country are in Louisiana.

Democrats, who hoped for significant gains in the election, picked up just six seats on Election Day and remain in the minority with 194 seats.

The political newcomer Applegate sought to portray Issa as an extremist and Trump foot soldier, while Issa framed his rival as a fringe liberal who would raise taxes and snatch guns from legal owners.

In a race in which Democrats sought to link Issa to Trump "people saw him as his own guy," said former Issa staffer Kurt Bardella. He's so well known in the district "it's a lot harder to tie him to anybody."

Preliminary returns show Clinton crushed Trump in the nation's most populous state by nearly 30 points.

The race between the car-alarm magnate and the soldier-litigator became a surprise after Applegate came within a handful of points of topping the veteran congressman in the June primary.

Francine Busby, chairwoman of the San Diego County Democratic Party, said no one in the party expressed interest in running because they saw no chance of winning.

"We were all astounded, including Applegate," Busby said. "He barely had run a campaign. It's just hard to run in a district where people don't see a viable race."

A decade ago, Republicans held a 20-point registration advantage over Democrats in the coastal district, which includes wealthy seaside enclaves north of San Diego but also densely packed, diverse suburban communities. That double-digit margin has dwindled to single digits, while the number of independents soared by 60 percent over that time.

Issa, the former chairman of the House Oversight and Government Reform Committee, had coasted to re-election seven times. His fortune from car-alarm manufacturing has been estimated at more than $250 million.