Media playback is unsupported on your device Media caption Conor Lamb: 'Mission accepted'

A Democrat has declared victory after a cliffhanger Pennsylvania election for a congressional district that Donald Trump won by 20 points in 2016.

There is no official result, but Conor Lamb and Republican opponent Rick Saccone were neck-and-neck in the solidly conservative 18th district.

Republican sway over the constituency is so strong that Democrats fielded no candidates in the last two votes.

The contest could set the tone for November's US mid-term polls.

Media playback is unsupported on your device Media caption This is why US gun laws probably won't change

Republican House of Representatives Speaker Paul Ryan called the race a "wakeup call" for his party.

With votes counted in every precinct of the working-class district, Mr Lamb was on 49.8% while Mr Saccone had 49.6%.

The Democrat was ahead by more than 600 ballots out of nearly 230,000 cast amid a nail-biting tally of absentee votes.

The 33-year-old claimed victory late on Tuesday saying: "It took a little longer than we thought but we did it. You did it."

Mr Saccone has not conceded the race.

Image copyright Reuters Image caption Mr Lamb is a 33-year-old socially-conservative Democrat and former federal prosecutor

Why is this election important?

The outcome could shape the contours of the mid-term elections, when Republicans will fight to keep their majority in both the US House of Representatives and the Senate.

Democrats need 24 seats to win back control of the House, which would be the first time they would control the chamber since 2010.

President Trump visited the 18th district in western Pennsylvania twice during the campaign, and Republicans spent millions of dollars to keep a hold of the seat.

Despite holding a rally in the district on Saturday, the president told those around him that he viewed Mr Saccone as a "weak" candidate, Axios reported.

The vice-president, the president's eldest son and daughter also visited the state to campaign for Mr Saccone.

Image copyright Getty Images Image caption Mr Trump has privately criticised the candidate as "weak"

Who are the candidates?

Marine veteran Conor Lamb, a former prosecutor, has promised not to support Democratic House of Representatives leader Nancy Pelosi and has taken up moderate positions.

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

Mr Lamb managed to out-fundraise his competitor by nearly 500%, and drew the support of blue-collar workers that Republicans had hoped to court with Mr Trump's new tariffs and tax cuts.

Mr Saccone, 60, is a four-term state lawmaker, Air Force veteran and former counter-intelligence officer who has referred to himself as Mr Trump's "wingman".

He was criticised late in the campaign after he said some of his opponents "have a hatred for God".

Mr Saccone also called himself "Trump before Trump was Trump".

The two competed to replace Tim Murphy, who resigned last October after admitting to 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?

Celebrations will be short-lived, as the winner must 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 constituencies in November's poll.

The new boundaries mean 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.