EASTLEIGH, United Kingdom — British Prime Minister David Cameron was under pressure Friday after his Conservatives were beaten into third place in a key election by his scandal-hit coalition partners and a eurosceptic 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.

The vote was sparked by the resignation of disgraced former energy minister Chris Huhne, a Liberal Democrat who has pleaded guilty to trying to avoid a speeding fine.

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 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.

“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,” the prime minister told the BBC.

The returning officer announced shortly after 0200 GMT on 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.

A jubilant Clegg told supporters in Eastleigh that they 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, but it is the centrist Lib Dems who have taken a far bigger hit in opinion polls than the centre-right Conservatives.

UKIP’s James said her second-place finish was a “humongous shock” that showed the party was now a major force in British politics.

Farage — a member of the European parliament who had reportedly considered standing in Eastleigh himself before backing out — said he was confident UKIP would win seats in the 2015 general election.

“If the Conservatives hadn’t split our vote we would have won,” he told the BBC.

He said Cameron had alienated voters by “talking about gay marriage, wind turbines, unlimited immigration from India (and) he wants Turkey to join the European Union.”

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.

But Cameron rejected the claims and dismissed talk that the party would now lurch to the right.

The 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 eurosceptic wing of his own Conservative party, but appeared not to have resonated with voters.