Labour held the Heywood and Middleton seat by just 617 votes as Nigel Farage claimed Ukip was "ripping lumps" out of the party in its northern heartlands. Ed Miliband's party had held the seat with a majority of almost 6,000 in 2010 but faced a recount before claiming victory in the by-election.
Ukip remains confident of securing its first elected MP in the Clacton by-election, triggered by Douglas Carswell's defection from the Tories. In Heywood and Middleton, Labour's Liz McInnes held off the challenge of John Bickley, with 11,633 votes to the Ukip candidate's 11,016 - a swing of 17.65% swing from Labour to Ukip.
Ukip had been campaigning strongly in the Lancashire constituency, in an effort to make inroads into Labour's northern heartland. The poll was triggered by the death of Labour MP Jim Dobbin, who had held the seat since 1997.
Mr Farage told Sky News: "We are ripping lumps out of the old Labour vote in the north of England. The truth of what has happened in the North today is that if you are anywhere north of Birmingham , if you vote Conservative you get Labour. And the reason we haven't won up there, despite a fantastic campaign, is that too many people have stuck with the Conservatives, not recognising that Ukip is now the challenger to Labour in every urban seat in the north of England."
Mr Farage said it was a "completely stunning result in Heywood and Middleton, which proves if you vote Conservative in the North, you get Labour". He indicated there could be further defections to Ukip in the months running up to the general election - without necessarily forcing a by-election.
"There comes a point where there will be backbench Conservatives, and perhaps some Labour ones too, who will reckon they have got a better chance on a Ukip ticket next year than a Tory or Labour ticket," he said. "I don't think we are quite at that moment yet."
Asked if they would be expected to resign as an MP, as Mr Carswell and his fellow Tory defector, Rochester and Strood's Mark Reckless, had done, Mr Farage said that might not be the case closer to the general election. "There is generally a six-month convention with these things, so if people were to come to us later than that there might not be."
In her acceptance speech Ms McInnes said voters "gave their backing to Ed Miliband's plan for an NHS with the time to care" and "they said to David Cameron, 'Keep your mitts off our National Health Service'." She added: "People here weren't convinced by Ukip - a party of Tory ideas, Tory people, Tory money and Tory values."
But Mr Bickley said: "Labour are in big trouble. This should have been a safe seat. They have thrown everything at it and they have only just scraped home. We would not have predicted four weeks ago to get so close. Most of the voters here in this constituency, particular the Labour voters, feel betrayed by the Labour Party.
"These are people who have been in the Labour Party all their lives and they look at the Labour Party and it no longer represents them. Another couple of days and I would have won this. We would have won a week from now on the back of Clacton."
Ukip is confident of victory in Clacton, with Tory Cabinet minister Eric Pickles appearing to accept that Mr Carswell would bear the Conservative candidate Giles Watling.
Mr Carswell held the seat with a majority of more than 12,000 at the 2010 general election and is expected to benefit from a strong personal following. Appearing on BBC1's Question Time Mr Pickles said: "I live in optimistic hope that a Conservative will be returned tonight, but I fear I will be disappointed."
Turnout in the Clacton by-election was 51.2%, acting returning officer Ian Davidson said. Mr Carswell said he "would not want to presume anything" as he made his way to the Clacton count. The Ukip candidate said he still had some "good friends" on the Tory benches, adding "friendship means a lot to me".
Asked by Sky News whether he could look them in the eye, he said: "I can certainly look myself in the mirror every morning."Suggest a correction