In a result that shocked even themselves, the Labour party retained the constituency of Glenrothes in a by-election yesterday.

The win is seen as a defeat for Scotland’s First Minister, Alex Salmond.

The SNP leader had visited the constituency regularly during the campaign and had seemed confident of overturning a 10,000 Labour majority.

The Nationalists won Glasgow East in a by-election in July from Labour, overturning a majority of more than 13,000.

The result in Glenrothes has been hailed by the Prime Mininster, whose Kircaldy and Cowdenbeath constituency is next door.

“What I have learned from this by-election is that people are prepared to support governments that will help people through the downturn and offer real help to people,” Gordon Brown said today.

There was a 52% turnout, which his high for a by-election.

Lindsay Roy, a highly respected local headmaster, and 58-year-old first time candidate, retained the seat for Labour with 19,946 and a majority of 6,737.

The SNP run the local council and Labour fought a negative campaign on their local government performance.  Mr Roy’s reputation in the constituency was also a key factor.

His lack of political experience was seen as an advantage with voters wary of professional politicians.

SNP candidate Peter Grant is leader of the council – he won 13,209. Tory Maurice Golden was third with 1,381 and Harry Wills for the Lib Dems won 947.

Tory leader David Cameron said the result was progress despite a fall of 3.3% support for the party since the 2005 general election and the candidate losing his deposit.

“The real loser is the Scottish National Party and as they want to break up our country, to destroy the Union that I’m passionate about, then maybe it’s no bad thing that the ‘Salmond bounce’ has disappeared,” he said.

“The Conservative Party has now established itself as the third party and that’s progress for us. We’ve still got a long way to go.”

The result is a major boost for Gordon Brown – until last night everyone, including Labour activists, though the seat was lost.