British Prime Minister David Cameron was under pressure after his Conservatives were beaten into third place in a key election last March first, by his scandal-hit coalition partners and a Euro-skeptic party.
Cameron admitted it was a disappointing night for his party after the Liberal Democrats held the parliamentary seat of Eastleigh in southern England in a contest billed as the most important British by-election in a generation.
The Conservatives had hoped at least to come in second but they were condemned to third place by the anti-European Union and anti-immigration UK Independence Party, which registered its best ever performance in a parliamentary election.
The vote was sparked by the resignation of former Energy minister Chris Huhne, a Liberal Democrat who has pleaded guilty to trying to avoid a speeding fine, but his disgrace did not harm the party's vote.
Deputy Prime Minister Nick Clegg, whose own position as Lib Dem leader had been on the line after a collapse in the party's poll ratings, said the stunning victory showed they can be a party of government and still win.
UKIP leader Nigel Farage meanwhile insisted the party's best ever result in a British election was not a protest vote.
Cameron said he was confident the Conservatives could win back support at the next general election, which is due in 2015, and rejected suggestions that the party would lurch to the right in response.
It is a disappointing result for the Conservative party but it's clear that in mid-term by-elections people want to register a protest he said.
The returning officer announced Friday that Lib Dem candidate Mike Thornton had secured 13,342 votes, 1,771 more than UKIP representative Diane James.
Tory nominee Maria Hutchings limped in third with 10,559 votes in a seat that the Conservatives held as recently as 1994, while the main opposition Labour party's candidate John O'Farrell was fourth with 4,088.
The Lib Dems overcame not only the Huhne scandal, but also an ongoing row surrounding the party's handling of claims that its former chief executive Chris Rennard molested female party members.
Visiting Eastleigh to congratulate Thornton, a jubilant Clegg told supporters his party had won the election in exceptionally difficult circumstances and that our opponents have thrown everything at us.
Two and a half years ago when we entered into coalition with the Conservatives our critics said we were going to lose our soul. Last night we proved those critics are emphatically wrong, Clegg told supporters.
The coalition has brought in a series of unpopular austerity measures to tackle Britain's record deficit. The centrist Lib Dems have so far taken a far bigger hit in opinion polls than the centre-right Conservatives.
The Eastleigh result came despite Cameron's pledge in January to renegotiate Britain's relationship with the European Union and then put British membership of the bloc to a referendum by the end of 2017.
The vow was supposed to head off both the threat from UKIP and the increasingly noisy Euro skeptic wing of his own Conservative party, but appeared not to have resonated with voters.
Farage -- a member of the European parliament who had reportedly considered standing in Eastleigh himself before backing out -- said the result showed UKIP was now a force in British politics.
If the Conservatives hadn't split our vote we would have won, he told the BBC.
The result meanwhile rekindled dissent among Conservative rebels.
Backbench lawmaker Eleanor Laing told BBC radio there was disquiet among her fellow Tory MPs and that many were in despair at the number of people resigning from the party.
Senior Conservative David Davis had earlier warned that third place for the party would be a crisis that would place serious doubt over Cameron's leadership.