Former Coronation Street actress and Labour candidate Tracy Brabin is standing in Batley and Spen by-election

David Cameron has congratulated his successor as MP for Witney, after the Conservatives survived a strong by-election challenge from the Liberal Democrats.

Barrister Robert Courts secured victory over Lib Dem Liz Leffman but saw the majority he inherited from the former prime minister slashed from more than 25,000 at last year's general election to just 5,702.

Jubilant Lib Dem leader Tim Farron hailed the 19.3% swing, which propelled his party from fourth to second place, as a return to the "political big time" after their disastrous general election performance.

"The result not only signals that the Liberal Democrats are back in the political big time and the return to three-party politics, it is a clear rejection of the Conservative Brexit Government's plan to take Britain out of the single market," said Mr Farron.

"This was the tenth safest Tory seat in the country with a massive 25,000 majority, yet the Conservatives were seriously rattled.

"They are riding high in the polls, but my sense is that has largely been because people did not feel there was a real opposition to the Conservative Brexit Government. Witney proves there is now a real opposition, and that opposition is the Liberal Democrats."

In his acceptance speech, Mr Courts paid tribute to Mr Cameron - whose decision to quit Parliament following his referendum defeat triggered the contest - as "a great prime minister and a brilliant MP" for the Oxfordshire constituency.

"It did not matter who you were, where you lived or how you voted, if you had a local issue then he was always happy to help and represent local people - that is something I will strive to do and to continue in my time as Member of Parliament," he said.

"Now we are going to move forward to build a country that works for everyone, our society should work for everyone, our economy should work for everyone and our democracy should work for everyone."

Mr Cameron responded with a message on Twitter: "Many congratulations Robert Courts - you'll be a great MP and representative for Witney and West Oxfordshire."

The Conservatives took 17,313 votes, just over 45% of the vote share - down from Mr Cameron's 60% in 2015 - while the Lib Dems with 11,611 received 30% of the vote, up from 6.8% last year.

Labour, with 5,765 votes, slumped into third place with just under 15%, down slightly from the 17% it had at the general election. All the other candidates lost their deposits.

The result will nevertheless alarm those Labour MPs who believe the party cannot win under Jeremy Corbyn, despite his crushing victory in last month's leadership contest.

There was better news for Labour in Batley and Spen, where former Coronation Street actress Tracy Brabin took 86% of the vote in a by-election to find a replacement for Jo Cox, who was killed in June.

Other mainstream parties did not stand in the contest out of respect for Mrs Cox, while a string of independent and fringe party candidates all lost their deposits.