media captionThe moment the Batley and Spen by-election results were announced

Labour's Kim Leadbeater has narrowly won the Batley and Spen by-election following a bitter campaign.

After defeating her Conservative rival by just 323 votes, she said constituents had "rejected division" and "voted for hope".

It means she will now represent the seat previously held by her sister Jo Cox, who was murdered there in 2016.

The result will ease pressure on Labour leader Keir Starmer after recent election defeats for his party.

Ms Leadbeater said the "vast majority" of her conversations with voters during the campaign were about local rather than national issues.

Asked whether Sir Keir had been an asset or a problem for her, she said: "The focus of the campaign was very much listening to local people."

The campaign in West Yorkshire was marred by acrimony, personal abuse and allegations of dirty tricks.

  • LIVE: Reaction to Labour by-election victory
  • Fraught by-election concludes in dramatic fashion
  • By-election campaigners 'egged and kicked'
  • Galloway legal threat over election poster fonts

Jo Cox's widower Brendan Cox said Ms Leadbeater had been "incredibly brave" to put herself forward, and he was "incredibly proud" of her.

"It was a very bruising and pretty horrible campaign at times," he added.

The contest was seen as an important test for leader Sir Keir, who welcomed it as a "fantastic result" will head to the seat on Friday to congratulate his party's victorious candidate.

It had been reported he may have faced a challenge from his deputy Angela Rayner if the party lost another northern English constituency to the Tories.

In May, the Conservatives took Hartlepool, a once rock-solid Labour seat, winning a by-election there with a majority of almost 7,000 votes.

This came in addition to the loss by Labour of more than 300 councillors in England's local elections.

Labour has held the seat of Batley and Spen since 1997, so a victory might well sound like it was expected.

However, there was an expectation Labour would lose and there were a number of factors working against them.

One was the fact that the Labour party has struggled in by-elections recently and lost Hartlepool, for example.

There was the fact that George Galloway stood here and he took 8,000 votes from traditional Labour voters in the Asian community, which is fairly sizeable in Batley and Spen.

The expectation in Westminster was that the Tories would sneak through the middle and win this seat – that hasn't happened.

Sir Keir Starmer will breathe a big sigh of relief, because if the Labour leader had seen another by-election loss today then he would have been in real trouble.

There would have been a lot of talk about leadership challenges, about the future of the party and about whether he had any prospect of really winning power at any stage if he was losing these by-elections halfway through a Conservative term.

The fact that hasn't happened means his supporters are in a pretty good mood this morning and they're saying this shows that some of the questions being asked of him over the last few weeks have been a bit over-hyped and that he can win.

In Batley and Spen Tory candidate Ryan Stephenson came second with 12,973, with former Labour and Respect MP George Galloway third with 8,264.

Speaking outside the count, Mr Galloway said he would apply to have the result set aside by the courts.

Sixteen candidates in total ran in contest. Turnout was 47.6%, with 37,786 verified ballots cast out of a total electorate of 79,373.

The contest was triggered after the previous Labour MP for the seat, Tracy Brabin, became West Yorkshire's first elected mayor in May.

She first won the seat in a by-election after Ms Cox was murdered by a far-right extremist in Birstall, part of the constituency, in 2016.