Liberal Democrats landed what Nick Clegg said was a "stunning victory" in the vote despite a turbulent week for the party amid allegations it failed to deal with claims of sexual harassment levelled at its former master strategist Lord Rennard.
But it was the surprise second place polled by the UK Independence Party (Ukip) in the contest that heaped humiliation on the Conservatives.
The Prime Minister acknowledged that the result was "disappointing" but dismissed it as a mid-term protest and insisted he would not now lurch to the right.
Some of his backbenchers, however, took to the airwaves to call for a change in direction from the top of the party.
Conservative MP Eleanor Laing, who described herself as having been "utterly loyal" during her parliamentary career, said many Tories felt "hurt" by the way they were treated by the leadership.
"They feel hurt and they feel left out," she told Radio 4's The World At One programme. "They're told that they're old-fashioned and they think that they don't matter and that what they stand for, and what they believe in, doesn't matter."
She said MPs were "in despair" about the number of people who are resigning from the party.
"Inevitably, when the fortunes of the party are not as good as they ought to be, then there is some disquiet," she added.
Mike Thornton won the by-election - triggered by the resignation of the Lib Dem's 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.
The poll was a major test for the Lib Dems, after Huhne's guilty plea for passing driving penalty points to his wife, and the claims hitting the headlines about Lord Rennard.
Mr Clegg said the message for Lib Dems from the poll was that "we can be in government and still win".
He told activists in Eastleigh: "We held our nerve, we stood our ground... we overcame the odds and we won a stunning victory."
Tory Maria Hutchings polled 10,559 votes - more than 1,000 behind Ukip, which snatched huge chunks of the coalition parties' 2010 general election vote share, taking more than 27% of the total.
Speaking in 10 Downing Street, Mr Cameron 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.
"I don't think we should tack this way, tack that way. What we have got to do is deliver for people who work hard, who want to get on, and deliver on the agenda that they care about and I care about."
Ukip leader Nigel Farage described the result as a "massive boost" and claimed Ukip would cause "an earthquake" in British politics.
"People will say it was a protest vote, but who we attracted here were non-voters who had not voted for 20 years - they are not protest votes," he said.
Labour's candidate, satirist and author John O'Farrell, polled 4,088 votes. Labour leader Ed Miliband said: "Clearly I would have preferred to have got more votes than we did, but this was always going to be a tough fight for Labour - it's a seat that we've never won."
The Hampshire seat is one of a list of 20 Lib Dem-held constituencies Tories believe are crucial for the party to win in 2015 to secure an outright majority.
Sarah Newton, deputy chairman of the Conservative Party, raised eyebrows when she tried to put a gloss on the result by branding it "good for the Coalition that the Coalition has kept a seat".
Tory rebel Douglas Carswell said the drubbing showed that policy changes were needed and questioned why the party was on a "long march of defeat".
Adam Afriyie, a Tory MP recently claimed to have been planning a leadership campaign, wrote on the conservativehome blog that the result was "a wake-up call for all of us" but suggested "sometimes failure is needed to refocus the effort to succeed".
Bob Woollard, chairman of Conservative Grassroots, which was created on the back of opposition to the Government's plans for gay marriage, said the party must return to "core Conservative values" to stand a chance of winning in 2015.
Conservative MEP Daniel Hannan said the Tories and Ukip should start "having conversations" about ways to avoid splitting the eurosceptic vote and called for the parties to "stop calling each other names". Mr Cameron once famously branded Ukip supporters "fruitcakes, loonies and closet racists".
Conservative Party vice chairman Michael Fabricant, who was heavily involved in the Eastleigh campaign, warned that support for Ukip could not be dismissed as a protest vote and that the party had managed to "connect" with blue collar Tories.
"The Conservative voice is muffled and not crisp. It does not clearly project Conservative core policies or principles," he wrote on his Twitter page.
"With Ukip clearly announcing policies the public want to hear, we must do the same. 26 months to go (to the next general election) boys and girls..."
Contextual targeting label: