Ukip has gained its second directly-elected MP with victory over the Conservatives in the Rochester and Strood by-election.

Mark Reckless, who defected from the Tories to spark the showdown with his former party, won by a majority of 2,920.

The result is a serious blow for David Cameron, who personally spearheaded the effort to put a brake on Ukip's recent surge with less than six months to go until the general election.

Mr Farage said the "massive, massive" win in what he called a "David v Goliath battle" meant "all bets are off" for 2015".

It comes just weeks after another defector Douglas Carswell romped home for Ukip in an identical contest in Clacton, Essex.

But the smaller-than-forecast margin of defeat may calm nerves that more eurosceptic backbenchers will be tempted to jump ship and join Nigel Farage's party.

Labour - which suffered a polling-day embarrassment with the resignation of shadow attorney general Emily Thornberry over what was called a "snobbish" tweet about an English flag-draped house in the constituency - came third.

And the Liberal Democrats continued a humiliating string of by-election performances, finishing fifth with just 349 votes and losing another deposit.

A total of 40,113 votes were cast - a turnout of 50.67%.

In his acceptance speech, Mr Reckless said: "If we can win here, we can win across the country. If you vote Ukip, you get Ukip."

And he told voters: "You remain my boss, don't let me forget it."

Mr Farage told reporters: "(David Cameron) put his own personal reputation on the line to fight this by-election and lost, so there you go."

Mr Reckless said his victory had proved that Ukip could win nationwide and urged voters to ensure enough MPs were elected to hold the balance of power after 2015.

"Whichever constituency, whatever your former party allegiance, think of what it would mean to have a bloc of Ukip MPs at Westminster large enough to hold the balance of power," he said.

"If you believe in freedom, if you believe in low taxes, if you believe in clean government, if you believe in localism, if you believe in people power.

"If you believe that the world is bigger than Europe, if you believe in an independent Britain, then come with us and we will give you back your country."

The MP sought to put behind him a controversy over his apparent suggestion that existing EU migrants could be forced to leave the UK if it pulled out of Europe.

He insisted that he had enjoyed "more than a dash of support from people who came here from other EU states".

"They are now here as part of our community and they will always be welcome," he added.

"If Ukip is to win nationwide - and we have proved tonight that we can - it must do so on that basis.

"We must be a party that speaks to and for the whole nation and everyone who lives within it."

Conservative Party chairman Grant Shapps said he was "disappointed with the result" and accepted that it would "make it harder to do the things we want to do in terms of controlling immigration, carrying on with this economic recovery".

But he said the narrower-than-predicted margin of victory for Ukip meant Tory candidate Kelly Tolhurst was well placed to wrest back the seat on May 7.

"Over the course of this campaign the gap has closed. They have ended up with about a 7% lead for Mark Reckless. They were predicting something over twice that level. So 2,900 is not a big majority now to try to win back in 170 days time," he said.

"I'm very sorry that Kelly has not been elected but with 2,900 votes in it, it certainly puts her in strong contention for the general election and we will be fighting very hard to win this back."

He told the BBC: "The future of this country ... wasn't on the ballot paper yesterday. It will be in 170 days' time.

"And that means that we really need to emphasise to people the risk of doing anything other than voting Conservative."

Analysis of the voting figures suggests that there will again be a hung Parliament after next May, however well Ukip performs.

No direct swing can be calculated as Ukip did not contest Rochester and Strood in 2010.

But the three major Westminster parties' vote shares fell by similar amounts compared with the last general election: Lib Dems by 15.39%, Tories by 14.39% and Labour by 11.70%.

In his victory speech, Mr Reckless said the large number of Labour voters who switched their support to him showed "the radical tradition, which has stood and spoken for the working class, has found a new home in Ukip".

"As Labour represents those comfortable at the top of the public sector, it is not Ed Miliband but Ukip that represents the concerns of most working men and women," he declared from the stage after a six-hour count.

It came after the Labour leader was forced to step in amid a furore over Ms Thornberry.

She sparked complaints by posting the image of the modern terraced house with three red and white Cross of St George flags and a white van in the drive along with the message "Image from Rochester".

After a social media and political backlash, she apologised after being given a dressing-down by leader Ed Miliband and Labour later announced that she had resigned her shadow cabinet position.

The owner of the house, Dan Ware, told The Sun: "I've not got a clue who she is, but she's a snob."

He said the flags had been left up since being raised when England played in the football World Cup in May.

Eurosceptic Tory backbencher Philip Davies denied that he was planning to defect despite admitting that he agreed with Nigel Farage "on nearly everything".

"The only way we are going to leave the EU is if we have a referendum. The only way we are going to have a referendum is if we have a Conservative government," he told BBC2's Newsnight.

Right-wing Conservative MP Stewart Jackson said: "Any Tory MP who defects to Ukip on the basis of the result in Rochester and Strood - whatever it is - would frankly be completely insane."

With 1,692 votes, the Green Party outpolled the Lib Dems by almost five to one to move into fourth place - almost trebling its share of the vote.

Mr Farage said he could not care less if any more MPs defect to Ukip.

Told that Tory MP Stewart Jackson had a point to suggest an MP would be insane to defect following the result, Mr Farage told BBC Radio 4's Today programme: "I expect Mr Jackson will lose his Peterborough seat next year.

"If he was to stand in Peterborough on a purple ticket for Ukip rather than a blue ticket he would increase his majority and be much safer.

"Look, it's up to them. I couldn't really care less. If people like Mr Jackson want to lose next year they can stick with the Conservative Party, but where you get seats where the Conservatives have a majority over Labour but there's a big Labour second vote then I think Ukip has a very strong chance of winning those constituencies.

"And my guess is this - I think there'll be a lot of sucking of teeth over the course of the next few weeks and there'll be Members of Parliament who work out actually they've got a better chance standing as Ukip.

"If they join us I'll be delighted, if they don't, frankly it doesn't really matter."

On what the latest by-election result means, Mr Farage said: "It means the whole thing is thrown up in the air. Anybody that now tries to attempt to predict what will happen next year is frankly wasting their time.

"It is now unpredictable beyond comprehension. This was seat number 271 on Ukip's target list. We've shown here if you vote Ukip, you get Ukip and I think the consequences are very difficult to predict."