Labour has narrowly seen off a Brexit Party challenge to hold on to its Peterborough seat in a by-election.
Union activist Lisa Forbes retained the constituency for Labour, taking 31% of the vote and beating the Brexit Party’s Mike Greene (29%) by 683 votes.
Ms Forbes said voters had “rejected the politics of division” and backed the “politics of hope”.
But Nigel Farage, who founded the Brexit Party less than two months ago, called its showing “very significant”.
The Conservatives came third with 21%, while the Liberal Democrats were fourth with 12%, followed by the Green Party on 3%.
• A total of 15 candidates stood
• Turnout was 48.4%, down from 67.5% in the 2017 general election, when Labour beat the Tories by 607 votes
• Voters in Peterborough backed Leave by 61% to 39% in the 2016 EU referendum
• Labour leader Jeremy Corbyn, former Prime Minister Gordon Brown and Tory big guns Boris Johnson and Jeremy Hunt visited the city during the hard-fought campaign
• Theresa May, who will officially resign as Conservative leader later, did not visit the constituency
The Peterborough by-election was called after Fiona Onasanya – who won for Labour in 2017 but was convicted of lying over a speeding offence and thrown out of the party – became the first MP to be ousted under recall rules.
As the winner was declared in Peterborough – usually a Labour-Tory marginal – shortly after 02:00 BST, cheers erupted from Ms Forbes’ supporters.
In her victory speech, she said her win had “shown that the politics of hope can win regardless of the odds”.
“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 Brexit Party had been the bookmakers’ favourite to take the Cambridgeshire seat – which would have been its first at Westminster – following its success in the recent European elections.
Its leader Nigel Farage said: “We have come from nowhere, produced a massive result – we haven’t quite got over the line, but we are pretty buoyed by this.”
He told BBC Radio 4’s Today programme the results indicated “the future is very, very unpredictable” – and that if the UK did not leave the EU on 31 October, “the Brexit Party will power on”.
Analysis by Lain Watson, Political Correspondent
The Brexit Party has made a huge impression – but history is written by the winners.
Had Nigel Farage’s party actually won this narrowly, he would have had much more momentum to argue not just to get Brexit done by the end of October, but to have huge influence potentially over how the Conservatives choose their leader.
Had Labour lost narrowly, there would have been a big demand from the rank and file for Jeremy Corbyn to sharpen his Brexit act and to call for a referendum under all circumstances. That has not happened either.
The conclusion that the Labour leadership is drawing from this is that people actually wanted to talk about things other than Brexit.
By talking about council cuts, crime, and education, they managed not to fight on the same territory as their opponents and were able to carve out their own distinctive message, get out their core vote and sneak over the line.
Asked about the party only having one policy – ensuring Brexit happens – and no manifesto, Mr Farage added: “We have a very strong, simple message that people believe in.”
Labour leader Jeremy Corbyn said it was a “great win” for a “people-powered campaign”.
“Peterborough has shown clear support for Labour’s programme to end austerity and invest in services and communities, rejecting a decade of Tory cuts and their disastrous handling of Brexit,” he said.
“In this key seat, the Conservatives have been pushed to the margins.”
Conservative leadership candidate Boris Johnson tweeted his “commiserations” to Tory candidate, who, he said, “did not deserve to come third”, while fellow contenders Dominic Raab, Matt Hancock and Jeremy Hunt said the result showed the threat from Labour.
Conservative Party chairman Brandon Lewis said the “clear message” from its poor performance in Peterborough as well as in recent council and European elections was the public wanted the government to deliver on the Brexit referendum result.
Polling expert Professor Sir John Curtice said the Peterborough by-election had not been as “dramatic” as the UK-wide European elections last month, in which the Brexit Party and Liberal Democrats came first and second.
But he added that the combined results had been “enough to disturb the regular rhythms of two-party politics”.
Ms Forbes caused controversy during the campaign when she liked a post on Twitter which said Theresa May had a “Zionist slave masters agenda”.
Shadow transport secretary Andy McDonald said she had been “careless” in her language but had apologised for her mistake and would make a fantastic MP.
But Labour MP Margaret Hodge said she had “raised concerns” about Ms Forbes’ comments with the party’s leadership, while fellow Labour MP Jess Phillips said Ms Forbes had “endorsed and ignored anti-Semitic things”.