The race between Republican Rick Saccone and Democrat Conor Lamb hung in limbo Tuesday night, hours after the polls closed in a special congressional race that had shined a light on western Pennsylvania and the Rust Belt politics that helped fuel the rise of President Trump.

With 99 percent of the vote counted, Mr. Lamb, a former Marine and federal prosecutor, clung to 49.9 percent to 49.5 percent lead over Mr. Saccone, a conservative state lawmaker, Navy veteran and former diplomat.

It amounted to a 579-vote lead out more than 220,000 cast. A few thousand absentee ballots still needed to be counted in some of the more GOP-friendly areas, leaving open the possibility for Mr. Saccone to score a come-from-behind victory.

SEE ALSO: Democrat Conor Lamb stakes claim on House seat before race is officially over

Mr. Lamb, though, declared victory before the final tally was known, thanking organized labor for its support and touting his campaign as a testament to the near universal approval of Social Security and Medicare.

“It took a little longer than we thought, but we did it,” Mr. Lamb told his supporters. “You did it! You did it!”

“We are practical people, we are serious people, and tonight we celebrate regaining our voice and our vote in the great business of governing this country we love,” Mr. Lamb said.

Before that, Mr. Saccone told his supporters at his election night party the race is not over yet.

“We are still fighting the fight,” Mr. Saccone told supporters at his election night party. “It is not over yet. We are fighting all the way to the end. You know I never give up.”

His remarks came almost four hours after the polls closed at 8 p.m. in the 18th Congressional District, which stretches from southwest suburbs of Pittsburgh to rural counties along the West Virginia border.

“This #PA18 situation is crazy: Nt only is a recount possible, but Lamb (D) & Saccone (R) must decide which district(s) to run for in the fall & collect 1,000 valid signatures before the filing deadline (3/20) in just ONE WEEK,” said David Wasserman, of the Cook Political Report, a nonpartisan election tracker.

Mr. Wasserman was alluding to how the winner of the race is set to serve out the remainder of the term of Rep. Tim Murphy, who resigned last year after engaging in an extramarital affair that included accusations he pressured his mistress to have an abortion.

But both of the men are considering running in newly drawn congressional districts outside the 18th, highlighting the symbolic nature of the race.

Whatever the case, the race was viewed as a barometer of the political climate 14 months into the Trump presidency and eight months out from the midterm elections, when the Republican House majority is on the line.

Republicans saw the race as a chance to show that Mr. Trump’s base of support is still solid among working-class voters who helped power the president to victory in key swing states.

The GOP also wanted to slow the momentum that Democrats carried out of Doug Jones’ victory in Alabama’s special Senate election last year and state legislative wins in red districts across the country.

Democrats, meanwhile, have been on the hunt for their first victory in a contested House election since Mr. Trump moved into the White House, after losing five in a row.

They were optimistic that a win — or even a narrow loss — in a district that Mr. Trump carried by 20 percentage points would be a good omen as they geared up for the midterm elections, where they believe the House GOP majority is vulnerable.

Democrats need to gain a net of 24 seats in the November election to take over the lower chamber.

“The fact that this race was competitive still tells us a lot about how bad the national environment has turned against Trump and the Republicans,” said Jesse Ferguson, a Democratic strategist.

Republicans said there is a lesson to be learned from the tight race.

“Win or lose, this is a wakeup call for Republicans,” said Courtney Alexander, spokesperson for the Congressional Leadership Fund, which spent $3.5 million on behalf of Mr. Saccone. “Candidates and campaigns matter.”

The vote tallies showed that Mr. Lamb, 33, was running strong in the suburban areas outside Pittsburgh, while Mr. Saccone, 60, was running strong in the more rural counties that have been GOP strongholds.

Thousands of absentee ballots were still be counted.

Mr. Trump invested heavily in the race, framing the contest as a referendum on the success his administration has had lowering taxes, cracking down on immigration and beefing up the military.

Mr. Trump said a vote for Mr. Lamb amounted to a vote against his agenda.

“The Economy is raging, at an all-time high, and is set to get even better. Jobs and wages up. Vote for Rick Saccone and keep it going!” Mr. Trump said on Twitter on Tuesday.

Vice President Mike Pence, and two of the president’s children, Ivanka and Donald Jr., also campaigned with Mr. Saccone.

Mr. Lamb got a helping hand from former Vice President Joe Biden and Rep. Joseph Patrick Kennedy, III, of Massachusetts, as well as former Gov. Martin O’Malley and House Minority Whip Steny Hoyer, both Maryland Democrats.

Mr. Lamb raised more money than Mr. Saccone. Half of the money he raised came from small-dollar donations that poured in from across the country from liberal activists eager to land a blow against Mr. Trump.

Mr. Saccone, however, was buoyed by more than $10 million spent by outside groups against Mr. Lamb.

Campaigning as “Trump before Trump was Trump,” Mr. Saccone said he was the most qualified for the job and stronger on the cultural issues — namely guns and abortion — that voters in steel country hold dear.

Mr. Lamb tried to steer clear of making the race about Mr. Trump and also distanced himself from national Democrats, saying it was time for Rep. Nancy Pelosi’s 15-year-reign as Democratic leader to come to an end.

Mr. Lamb said he did not support expansive gun control efforts following the mass shooting at a Florida high school and split with Mr. Saccone over Mr. Trump’s $1.5 trillion tax cut.

Mr. Lamb said the tax cuts did not do enough for working families and would result in deficits. He warned the GOP would target Social Security and Medicare and vowed to stand with labor unions.

Democrats previously had lost contested special election House races in Kansas, South Carolina, Montana, Georgia and Utah.