Liberal Democrat leader Nick Clegg has hailed his party's success in the Eastleigh by-election, telling activists in the Hampshire town: "We held our nerve, we stood our ground... we overcame the odds and we won a stunning victory."

The Lib Dems held off a late surge by the UK Independence Party (Ukip) to win the by-election in the early hours of this morning, but Prime Minister David Cameron was dealt a serious blow as the Conservatives were pushed into third place.

Mr Cameron acknowledged that the result was "disappointing" for his party but insisted he was "confident" that in the 2015 general election the Tories would be able to win back the protest voters who deserted them last night.

Speaking in 10 Downing Street, the Prime Minister said: "It is a disappointing result for the Conservative Party, but it is clear that, in mid-term by-elections, people want to register a protest.

"But I am confident that at the general election we can win those people back by demonstrating that we are delivering for everyone who wants to work hard and wants to get on. That is what we will be focused on."

Visiting Eastleigh to congratulate his party's new MP, Mike Thornton, Mr Clegg said the message for Lib Dems from the poll was that "we can be in government and still win".

Mr Thornton won the by-election - triggered by the resignation of disgraced ex-Cabinet minister Chris Huhne - with 13,342 votes, a majority of 1,771 over Ukip's Diane James, who said beating the Tories was a "humongous" shock which represented a "seismic shift" in UK politics.

Jubilant Lib Dem president Tim Farron said the result meant that 20-30 Tory seats were now vulnerable to the party in the 2015 general election.

But Conservative Education Secretary Michael Gove insisted that the party would not be blown off course by its defeat and would resist backbench calls for a shift to the right on issues like immigration and gay marriage.

"What we need to demonstrate is that the course that we have set is producing results," Mr Gove told the BBC Radio 4 Today programme.

"If people think you are changing policy in order to take account of a by-election or to play party politics, that is when the problems arise and people think 'Do you know what? We smell inauthenticity here'."