All sides had predicted a close result, but Labour's candidate Lindsay Roy coasted to victory with a majority of 6737.
And the SNP was left licking its wounds, having achieved only a five per cent swing in their favour compared withe the 22.5 per cent which saw them storm to victory in Glasgow East in July. Labour also held off an
SNP challenge to win the council by-election in Edinburgh's Forth ward caused by the death of Labour stalwart Elizabeth Maginnis.
Scottish Labour leader Iain Gray said: "The honeymoon is over.
"The SNP's broken promises and empty bluster are now coming home to roost.
"Their arguments for breaking up Britain have been exposed by the economic crisis, which has demonstrated that Scotland's best future lies in partnership with the rest of the UK."
First Minister Alex Salmond had predicted Glenrothes would be another political "earthquake" following the SNP's Glasgow East triumph.
But although the Nationalists managed to reduce Labour's previous majority of 10,664 majority, both parties saw their share of the vote increase at the expense of the minor parties and Labour was able to maintain a clear lead.
It is the first serious electoral setback for the SNP since it won last year's Scottish Parliament elections.
Mr Salmond said: "Obviously, we are disappointed not to take what was a safe Labour seat.
"However, we substantially cut Labour's majority and achieved a 13 per cent increase in our share of the vote and a five per cent swing against an entirely negative campaign on local issues from the Labour Party."
Labour's victory is being seen as a huge personal boost for Prime Minister Gordon Brown. His Kirkcaldy and Cowdenbeath constituency is next door and he broke with convention to join the campaign in Glenrothes along with his wife Sarah.
Labour's Scottish Secretary Jim Murphy hailed what he described as a "remarkable" result and accused the SNP of arrogance.
He said "The SNP declared victory the day the by-election was called. Their campaign went from confidence to arrogance and I don't think the people of Fife or Scotland appreciated that.
He said the Prime Minister's handling of the global financial crisis had encouraged voters to support Labour again.
He said "It is a dreadful result for the SNP. They had predicted they would win. Their leader Alex Salmond visited the constituency 12 times.
"Labour had more votes in the election yesterday than in the General Election, which is a reflection of the affection that Gordon Brown is held in and a reflection of the appreciation of the work that he has been doing in the UK and across the world on the economic crisis."
The Tories leapfrogged the Lib Dems to take third place, but both parties lost their deposits.
New MP Lindsay Roy, who will now resign his post at head teacher of Gordon Brown's old school, Kirkcaldy High School, thanked the Prime Minister for his support.
He said: "I pledge my support to the leader of this country. Someone who has worked very hard on behalf of all of us, not just in Fife, but in Scotland and the UK during these volatile economic times."
Supporters cheer 'reluctant politician'
BOOKMAKERS declared the by-election too close to call as officials, activists and the waiting media prepared for the votes to be counted.
Many expected the SNP to repeat its historic win in Glasgow East, but all evidence pointed to the fight for the Glenrothes seat being a close race.
Labour's 59-year-old candidate, quiet, measured high school headteacher Lindsay Roy was described by one onlooker as a "reluctant politician" who may be keen to run the constituency but for whom sitting in Westminster could be a different story.
Peter Grant's leadership of Fife Council, which has faced criticism over recent policies on homecare charges, was also a hot topic on the floor of the count centre.
The first ballot box arrived at the count centre at Fife Institute of Sport shortly after 10.15pm and photographers and television crews jostled for position to get a shot of the moment the count began.
An air of anticipation filled the sports hall and party activists gathered round the counting tables, eagerly awaiting a hint of how the electorate had voted.
Each of the eight candidates standing had strong support in attendance, with Tricia Marwick who won the Central Fife seat for the Nationalists in last year's Holyrood election. Frank Roy, Labour MP for Motherwell and Wishaw, and Scottish Conservative deputy leader, Central Scotland and Fife MSP Murdo Fraser among those showing support at the count.
A steady stream of black ballot boxes sealed with yellow security tags were wheeled to the teams of counters, despite a hold up as a car awkwardly parked prevented vans containing votes from unloading at the count centre. The by-election prompted an "unprecedented" level of media interest, with 170 media accreditations compared with 140 in 2005 when then Chancellor, Gordon Brown, was returned to Westminster.
Less than two hours after polls closed, rumours of a shock Labour win came with the completion of verification process, where activists from each party watch counters and tally votes.
When Lindsay Roy arrived at 12.30am he was met with cheers and applause from waiting supporters. Peter Grant's arrival with wife and fellow SNP councillor Fiona Grant five minutes later went almost unnoticed as Labour activists welcomed their candidate.
When the result was announced by returning officer Ronnie Hinds, cheers rang round the Fife sports hall.
The unassuming new MP has pledged to match the work done by John MacDougall, whose death prompted the by-election.
Balance of power is unchanged as Day retains Forth ward seat
LABOUR has maintained the balance of power in Edinburgh Council by retaining the Forth ward seat left vacant by the sudden death of councillor Elizabeth Maginnis.
The party's 34-year-old candidate Cammy Day held the council seat for Labour with a majority of 172 votes over the SNP's second place candidate George Gordon.
The SNP had hoped to snatch the seat away from Labour to give the ruling SNP / Lib Dem coalition a clear majority for the first time in the chamber, but it was not to be. It means that the coalition will have to continue to rely on the casting vote of Lord Provost George Grubb to break the deadlock in crucial decisions.
Mr Day, formerly a youth worker in the area, paid tribute to Ms Maginnis, who died suddenly in September, and promised to "carry on her fighting spirit" for the people of the Forth ward.
He said: "I'm shocked, elated and shaken to have won the by-election.
"I think the result shows that the people of Forth have seen that Labour is the true fighting party of Edinburgh.
"I hope to bring to the council what Elizabeth Maginnis brought to the council, which is a fight.
"The key issue for us right now is to continue to fight the ruling administration's cuts in local services."
Mr Day added that he will also fight to clean up the streets in areas like Granton and will campaign for more police on the streets of Forth.
He added: "I'm younger than Ms Maginnis and I hope to use this, alongside my experience as a youth worker, to engage young people into politics."
Like Ms Maginnis before him, Mr Day was selected at the ninth stage of the council's single transferable vote (STV) system, meaning he failed to achieve the required 50% of the vote until the final stage of selection.
Labour group leader Andrew Burns paid tribute to his candidate's "inspiring victory".
However, City Council leader Jenny Dawe indicated that the protracted STV selection process demonstrates that the result was not an all-out endorsement for Labour.
She said: "The fact that the result went down to the final round of selection tells its own story."
Presiding officer Tom Aitchison said the voting process went smoothly, with none of the electronic voting problems that marred the full council elections in 2007.
Voter turn out was roughly 40% down on last year's election, and this was reflected in the results with most of the parties maintaining their relative share of the diminished vote.
While the night was Labour's, the biggest cheer was reserved for former Scottish Youth Parliament chairman and Big Brother: Celebrity Hijack winner John Loughton, who won 297 votes standing as an independent.
Mr Loughton's engaging spirit went down well with all parties, and Cammy Day vowed to work with him to energise the youth vote in the ward.
Mr Loughton said: "Nearly 300 people voted for an individual and a set of beliefs rather than a party. That is what politics is all about."