The two are competing to replace Tim Murphy, who resigned last October.

But celebrations will be short-lived, as the winner will begin campaigning for a seat in a different district.

Due to new district boundaries imposed by the state Supreme Court in January, the 18th district will be split up into four different districts in November’s poll.

Why is the race important?

With votes counted in every precinct, Mr Lamb has 49.8% – just ahead of Mr Saccone (49.6%).

The gap between the two rivals is just a few hundred votes, and absentee ballots are now being counted.

Despite this, Mr Lamb claimed victory late on Tuesday. “It took a little longer than we thought but we did it. You did it,” he told his supporters.

But Mr Saccone has not conceded the race, and there are no official final results.

The outcome could set the tone for November’s mid-term elections, when Republicans will fight to keep majority in both the US House of Representatives and the Senate.

President Donald Trump won the working-class Pennsylvania district by more than 20 points in the 2016 presidential election, but the race has become unexpectedly tight despite his efforts.

The president has visited the district twice during the campaign, while Republicans have spent millions of dollars to keep a firm Republican grasp on the seat.

Media playback is unsupported on your device

Media captionThis is why US gun laws probably won’t change

The vice-president, the president’s eldest son and daughter have also visited the state to campaign.

Meanwhile, a Democratic victory could add momentum to the party’s hopes of capturing control of the House of Representatives in November.

Who are the candidates?

Marine veteran Conor Lamb, a 33-year-old former prosecutor, has promised not to support Democratic Congresswoman Nancy Pelosi and has taken up relatively conservative positions for his party.

Image copyrightReutersImage caption Mr Lamb is a 33-year-old socially-conservative Democrat and former federal prosecutor Image copyrightReutersImage caption Mr Saccone has aligned himself with President Trump, who won handily won the district in 2016

He has said he opposes new gun restrictions, but backs expanded background checks, and declared himself personally opposed to abortion.

His Republican opponent Rick Saccone, 60, is a four-term state lawmaker, Air Force veteran and former counterintelligence officer who has referred to himself as Mr Trump’s “wingman”.

The district’s previous lawmaker, Republican Tim Murphy, resigned last year after admitting to having an extra-marital affair.

‘The wave is out there’

Analysis by BBC North America reporter Anthony Zurcher

If the 2018 congressional mid-terms are a coming electoral tsunami in favour of the Democrats, Tuesday’s Pennsylvania special election was the ocean water receding beyond the horizon.

The wave is out there, and it may only be a matter of time before it comes crashing down on the Republican Party. The results in Pennsylvania are razor thin and could still tilt either way.

Given the nature of the district, however, it shouldn’t have been close. Republicans drew the boundaries in 2011 to give themselves a safe seat.

In two recent elections, Democrats didn’t even field a congressional candidate. In 2016, Donald Trump carried the district by 20 points.

Now, the political pendulum is swinging toward the Democrats in a very big way. White working-class voters, who rallied to Mr Trump, either didn’t vote or opted for the Democrat.

There’s still time for Republicans to respond, of course. And the mid-term electorate may be different than the one that shows up for a special election in March.

If seats that look like this Pennsylvania district are toss-ups in November, however, a lot of Republican candidates are going to get swept away.

What’s happening to the district?

The winner will have to turn his attention to a new race ahead after a victory party draws to a close.

The new boundaries imposed by the state’s high court means the district will not exist in its current form in November.

The winner will serve out the rest of the year and then have to begin campaigning in one of the newly drawn districts. The deadline to file to run in November is 20 March.