EASTLEIGH (Reuters) - Prime Minister David Cameron's Conservative Party has been beaten into third place in a vote in southern England by a party that wants Britain to leave the European Union, prompting some lawmakers in his party to question his leadership credentials.
The UK Independence Party has no MPs and Cameron once described its members as "fruitcakes, loonies and closet racists", but UKIP came second in Thursday's election for the parliamentary seat in Eastleigh, winning its biggest share of the vote ever.
To compound Cameron's misery, the Liberal Democrat party, the junior partner in his governing coalition, took first place despite being embroiled in high-profile sex and perjury scandals and floundering in national opinion polls.
The result has piled pressure on Cameron from disgruntled lawmakers within his own party who fret he may not be able to lead them to victory in a 2015 national election. Many feel he has turned his back on the kind of traditional Conservatism espoused by former Tory leaders like Margaret Thatcher.
"He's got a very limited amount of time to rekindle the love with the grassroots who will be crucial to win a general election," Stewart Jackson, a Conservative MP, told Reuters.
"For too many of the people who consider themselves Tories, the leadership seems too liberal and elitist. Cameron has got some work to do."
The Conservatives had hoped to win or at least come second in Eastleigh, which is in the county of Hampshire southwest of London, but Cameron played down the defeat.
"This is a by-election, it's mid-term, it's a protest. That's what happens in by-elections," Cameron said.
"It's disappointing for the Conservative Party but we must remain true to our principles, true to our course, and that way we can win people back. I don't think we should tack this way, tack that way."
However, Nigel Farage, leader of UKIP, said the vote showed his party was on the verge of a "national political earthquake".
"It's a protest against an entire political class who are not willing to confront difficult issues like open-door immigration," Farage told a news conference on Friday.
Education Secretary Michael Gove, a Conservative, said disillusionment with mainstream politics and anger at Britain's economic woes had played a role in the defeat.
The result was an important win for the Liberal Democrats and Nick Clegg, the deputy prime minister and party leader, whose leadership has come under pressure in recent weeks.
They polled 13,342 votes, UKIP 11,571, the Conservatives 10,559 and the Labour Party 4,088. That meant UKIP took almost 28 percent of the vote.
Since becoming leader, Cameron has sought to ground his party in the centre of British politics, but some Conservatives believe in doing so he has alienated traditional supporters over issues such as his support for gay marriage, which UKIP opposes.
"He took the base of his party for granted and just reached out with centrist messages. He sowed the seeds for the problem he now has, which is this growth of UKIP," said Tim Montgomerie, editor of the influential ConservativeHome website.
"I don't suspect UKIP will take a single seat at the next general election. But if they win six, seven, eight percent of the vote which opinion polls and results like this are beginning to suggest they can, they will prevent us getting a majority."
A winner-takes-all constituency voting system makes it hard for small parties to gain seats in the London parliament.
Eastleigh does not directly reflect national sentiment - a YouGov poll in the Sun tabloid on Friday put the opposition Labour party on 42 percent, the Conservatives on 29 percent, the Liberal Democrats 12 percent and UKIP 11 percent.
But heavy austerity measures, combined with an ailing economy heading for its third recession in four years, have sapped support for Cameron, who formed a coalition government with the Liberal Democrats in 2010.
Last week's decision by Moody's to strip Britain of its coveted top-notch triple-A credit rating was an embarrassment and again raised questions about Cameron's leadership. Some Conservative MPs have begun to openly question it.
Farage's party has siphoned off support from traditional Conservatives by denouncing EU bureaucracy and immigration from eastern Europe, tapping into what he says is a widespread feeling that voter concerns have been ignored.
Under pressure from UKIP, Cameron has promised to hold an "in-out" referendum on Britain's membership of the EU by the end of 2017 if he wins the next election, a move his supporters had hoped would steal UKIP's thunder.
Commentators said the election would help stabilise the coalition in the short term, as Clegg's leadership of the Liberal Democrats, without whom the right-wing Conservatives cannot govern or pass legislation, had faced intense pressure.
Irene Cook, 66, a retired shop assistant who voted UKIP, said the party's policies on immigration had attracted her.
"We wanted Britain to stay Britain. We didn't want any more immigration of other people coming in from other countries. It's got to stop. We're only a small island anyway. We voted for them, and I'm very, very pleased, they've done very well."
Writing by Michael Holden and Andrew Osborn; Editing by Guy Faulconbridge and Mark Heinrich