Nigel Farage's new Brexit Party has failed to secure its first MP as Labour took the Peterborough by-election in a closely-fought contest.
The Brexit Party, which launched less than six months ago, was beaten by just 683 votes as the Conservatives fell back into third place.
The constituency, which voted 60.9% for Leave in the 2016 referendum, had been regarded as potentially fertile ground for the new party.
But with a relatively high turnout for a by-election of 48.4%, it appears that they were unable to match Labour's organisation on the ground.
Mr Farage made a brief appearance at the count – apparently anticipating victory – but left without talking to reporters.
In a tweet, the party said it was a "remarkable result" for such a new organisation.
"If we can come so close in our 201st target seat, no seat is safe," it said.
The result came as a huge relief for Labour after their dismal showing in last month's European elections amid complaints they had failed to offer a clear line on Brexit.
Jeremy Corbyn said it was a "great win" and represented a rejection of the Conservatives' "disastrous" handling of Brexit.
"In this key seat, the Conservatives have been pushed to the margins," he said.
"This result shows that in spite of the divisions and deadlock over Brexit, when it comes to a vote on the issues that directly affect people's lives, Labour's case for real change has strong support across the country."
Labour won 10,484 votes to the Brexit Party's 9,801, with the Tories on 7,243 votes in a seat which has traditionally been a two-way Conservative-Labour marginal.
The Liberal Democrats were fourth with 4,159, while the Greens came fifth with 1,035 votes.
However Labour's vote share fell by more than 17 percentage points from the 2017 general election, while the Conservatives were down by more than 25 percentage points.
In her victory address, the winning Labour candidate Lisa Forbes hailed the result as a defeat for the Brexit Party's "politics of division".
"Despite the differing opinions across our city, the fact that the Brexit Party have been rejected here in Peterborough shows that the politics of division will not win," she said.
The defeated Brexit Party candidate Mike Greene admitted they had been unable to match Labour's established organisation in the constituency.
However he insisted that they would continue to build on the momentum from their triumph in the European elections when they topped the poll.
"Two parties have been ruling this country for decades. That is not happening any more. We were ahead of the Tories, only 683 votes behind Labour," he told Sky News.
"They have decades of data. We had nothing just four weeks ago. We did not have the vote numbers they had. We didn't have the voting history they have.
"We will be back. Let's see what does happen in the next general election."
The by-election was called after Peterborough's previous MP Fiona Onasanya was forced out after she was jailed for lying about a speeding offence.
Onasanya was elected as a Labour MP in 2017 with a wafer-thin majority of 607 but was suspended from the party after she was sentenced.
Among local Tory activists there was frustration that the continuing turmoil over Brexit meant they were unable to take advantage of Labour's difficulties.
The chairman of the Peterborough Conservative Association Wayne Fitzgerald said it was now essential the party committed to taking Britain out of the EU, even if it meant no deal.
A remarkable result for our 8 week old party. If we can come so close in our 201st target seat, no seat is safe. We're very proud of @MikeGreeneTBP & our supporters who worked so hard. Thanks to the people of Peterborough who voted for us – we promise you that we're here to stay! pic.twitter.com/ARmLuADZ1P
— The Brexit Party (@brexitparty_uk) June 7, 2019
"Parliamentarians in Westminster are against the will of the people," he told Sky News.
"The Conservatives must de-select every MP who will not accept a WTO (World Trade Organisation) Brexit if it comes to that.
"If Boris (Johnson) or whoever is leader doesn't do that, Mr Farage will sweep to 450 seats in the next general election."