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.
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 per cent 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 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.”
Ms McInnes said: “I am proud to have been selected as the new MP for Heywood and Middleton. Our vote held up, we had not anticipated the Tory vote collapsing quite so dramatically. But our core voters turned out. We didn't take anyone's votes for granted and we have run a very strong positive campaign.”
Asked if she expected Ukip to run have Labour so close, she said: “To be honest with you I have been through more or less every scenario. As I said before, we don't take anyone's vote for granted. We work very hard and I am just pleased our vote held up. We can't choose our opponents.
“I am proud and honoured to have been selected for this area. I am not disappointed that the majority has been reduced. I knew this was going to be a tough fight and we have run a really strong positive campaign and we have fought for every single vote.”
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies