Labour candidate Lisa Forbes won the Peterborough constituency in eastern England by 683 votes over the Brexit Party's Mike Greene.
The result, announced Friday, is a blow to the momentum of the months-old Brexit Party led by former UKIP leader Nigel Farage.
The party wants Britain to leave the European Union, with or without a divorce deal. That message has resonated with Brexit-backing voters angry at the country's political deadlock. The party won almost a third of U.K. votes in last month's European Parliament election.
The election was called after Peterborough's previous Labour lawmaker was jailed for lying about a speeding offense.