Relieved Liberal Democrats have claimed a narrow victory in the Eastleigh byelection, fending off a surge by Ukip that forced the Conservatives into third place – putting huge pressure on David Cameron to show he has a strategy to win the 2015 election.
The Liberal Democrat candidate Mike Thornton won the seat with a majority of 1,771, taking 13,342 votes to Ukip's 11,571.
The Tories' candidate Maria Hutchings came in third with 10,559. Labour's John O'Farrell came fourth with 4,088. The Liberal Democrat share of the vote fell by 14.5%, the Ukip share rose 24.2 %, the Tories fell 14% and Labour went up 0.2%. Turnout was 52.8 %.
Nick Clegg, facing growing questions over his own leadership, will regard it as a stunning triumph that his party survived against the backdrop of the previous Lib Dem MP Chris Huhne resigning and now facing a prison sentence for asking his wife to take speeding points.
Clegg also faced a week-long media barrage in the run-up to polling day over his handling of allegations of sexual impropriety by the party's former chief executive, Lord Rennard.
The former party leader Paddy Ashdown praised Clegg's resilience, saying he had withstood "the most ravenous media feeding frenzy I have ever experienced as a Lib Dem in 40 years of politics".
Simon Hughes, the Lib Dem deputy leader, said the result showed the party could retain its fortresses at the 2015 election, and was a victory for its local organisation. An even more ebullient party president Tim Farron claimed: "This is a staggering result and the people who had written us off will have egg all over their faces. It will be a turning point in this parliament and that we are in a position to win this seat completely changes the narrative of the parliament".
Thornton praised the effective fighting spirit in his party.
The Conservative failure in Eastleigh raises searching questions over whether Cameron has a credible strategy not just to topple the 15 Lib Dem-held seats needed to secure an overall majority, but also to prevent Ukip as the new party of protest gnawing into his wider vote in the next general election.
Tim Farron, the Liberal Democrat party president, said the result would send "ripples of confidence" out to activists across the country. "We've had thousands of people down here to help. I've had people who had left because of the coalition rejoin for Eastleigh. It has been immense. The message to Tory and Labour is come and have a go if you want. We'll have you in our backyard. We're here to stay.
"Nick's position is much strengthened not just in the party but in the country as well. The idea that the Liberal Democrats are going like lambs to the slaughter is not true."
He said it had been a "shocking" result for both the Tories and Labour, adding that he imagined it would trigger a leadership crisis for Cameron. "I think they'll learn all the wrong lessons, they'll think 'We're not mad enough. Let's become more extreme.'"
But Farron said the result showed the Lib Dems had to take Ukip seriously though their policies on Europe were "certifiable".
John Denham, Ed Miliband's parliamentary private secretary and the man charged with getting Labour into a position to win seats in the south of England, said the party had learned from the campaign. He said the Ukip success showed that immigration was a "serious issue for many voters".
"People were concerned about migration. We've got to continue to talk about how we tackle those issues. At the moment not all voters are hearing what we're saying," Denham said.
"It seems to me it's a catastrophic result for the Tories. They needed to win it. To come third leaves them in a very difficult position. Do they go after the Ukip votes in which they make it even harder to win the centrist votes in constituencies like this?"
All the mainstream parties will now have to decide whether to respond to Ukip's growing popularity by becoming more Eurosceptic and anti-immigrant, or instead challenging the party as an empty vehicle of protest. The Tory rightwinger David Davis had already warned that it would represent a crisis for Cameron if Ukip came second, and Cameron will now battle to retain discipline. The prime minister had hoped he had immunised himself from the Ukip threat by promising a referendum on EU membership after the 2015 election, and highlighting measures to keep out EU migrants. Cameron had also selected a rightwing candidate opposed to Europe and gay marriage. But this byelection showed it did not work and they will now have to rethink their strategy. The result also places even more pressure on George Osborne, the chancellor, to deliver a budget in March that lifts growth and living standards.
The Ukip candidate, Diane James, said: "The result was momentous. Three weeks ago we said we wanted to create a four-way marginal what we have done is create a two-way marginal. To have come from absolutely nowhere to achieve that is a fantastic result".
Nigel Farage, Ukip's leader, promised to put 2,000 candidates into the field in the May county council elections, insisting that "this was not a freak result, but shows that something is moving".
He predicted border controls and immigration will become central to the future EU debate in the UK, and claimed a "political earthquake" was coming.
The Conservative chairman Grant Shapps said it was rare for a governing party to capture a seat, but insisted that "come a general election voters will make a choice between whether they wanted David Cameron or Ed Miliband walking up Downing Street".
He insisted his backbenchers "will recognise that this was a typical byelection result. Look at the history of byelections throughout the ages - midterm governments tend to get a drubbing". He added: "All the evidence is that in two and a half years, things can change. We have to redouble our efforts so by the next general election we have a story to tell about the global race for Britain, and how the Conservative party is leading the charge to ensure we are in the right place on the issues that matter, including the ones about which Ukip voters are concerned.
"It leaves the Labour party and Ed Miliband with all the difficult problems to answer about why he is not making any progress in areas of the south"
Labour came a disappointing fourth, but denied the result casts a shadow over Ed Miliband's claims that his vision of One Nation Labour has enough content to appeal in southern England. In 2010, Labour won nearly 10% of the vote in Eastleigh, but instead of Labour becoming the vehicle for a protest against the government, Ukip – which had 3.6% share in 2010 – has surged past Labour.
Labour admitted immigration had been the main national issue on the doorstep, and Miliband is to dedicate a TV political broadcast to the issue next Wednesday,
Labour insisted it could still win its target seats in the south but added that in Eastleigh it simply did not have the local base in a short campaign to match the Lib Dems' ground operation.
The Lib Dems poured thousands of activists into the seat, they have a stranglehold on the council and Clegg visited the constituency five times.
But as recently as the 1994 byelection, when there was a Conservative government and Labour were the main opposition, Labour secured 27.6%.
In 2005, when Labour last won a general election, they scored 20.6% in Eastleigh.
guardian.co.uk © Guardian News and Media Limited 2010
image: © Liberal Democrats