Labour has won the Glenrothes by-election, comfortably holding off a challenge from the SNP.
Lindsay Roy was elected the new MP with a majority of 6,737 over the SNP's Peter Grant.
The Tories came third with 1,381 votes while the Lib Dems, who polled 947 votes, were squeezed to fourth.
Prime Minister Gordon Brown said victory in the Fife seat was a vote of confidence in the government's handling of the economic crisis.
ELECTION RESULTS
Results in full Lindsay Roy, Labour: 19,946 Peter Grant, SNP: 13,209 Maurice Golden, Cons: 1,381 Harry Wills, Lib Dem: 947 Jim Parker, SSCUP: 296 Morag Balfour, SSP: 212 Kris Seunarine, UKIP: 117 Louise McLeary, Solidarity: 87 Labour majority: 6,737 Turnout: 52.34%
The by-election was held after the death of sitting Labour MP John MacDougall.
The constituency borders the Kirkcaldy and Cowdenbeath seat held by Mr Brown, who visited Glenrothes several times during the by-election campaign.
Despite Labour's majority in Glenrothes in the 2005 UK election being cut from 10,664, the party pulled through to win with 19,946 votes to the SNP's 13,209.
The new MP for Glenrothes praised Mr Brown.
Mr Roy, 59, who will quit as the rector of Kirkcaldy High School to take up his Westminster seat, said: "With Gordon Brown, Britain is strong. With Gordon Brown, Labour has won here in Glenrothes and central Fife."
The prime minister said: "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.
"They are less willing to support people who have no idea about how to solve the problems we have got."
Mr Grant, the leader of Fife Council, failed to repeat the Nationalists' success in the Glasgow East by-election in July, where his party won what was then one of Labour's safest seats.
He said: "We have seen the SNP vote in this constituency increase by almost 50% on what it was a few years ago."
Mr Grant stood by controversial home care charge increases brought in by his council, a big campaign issue.
BBC Scotland political correspondent Brian Taylor said: "Labour attacked the Nationalists day and daily over claims that the SNP-led administration in Fife Council had cut home care services for the most vulnerable.
"In vain did the SNP protest that this was driven by externally imposed exigencies, that they were doing nothing different from several other councils (including Labour ones) and that they had increased the budget in key areas of expenditure."
Deputy First Minister Nicola Sturgeon conceded that the result was a "very disappointing" one for the SNP.
She told BBC Radio 4's Today programme: "We ran a very good campaign, we fought hard and had an excellent candidate, and we are very disappointed not to have won the seat."
Ms Sturgeon dismissed any suggestion the SNP had taken victory in the seat for granted, and accused Labour of running a "relentlessly negative" by-election campaign that focused on a single local issue, home care charges.
Meanwhile, both the Tory candidate Maurice Golden and Liberal Democrat candidate Harry Wills lost their deposits.
"This was a victory for Lindsay Roy, not for Gordon Brown," said Mr Golden, adding: "The Alex Salmond bubble has well and truly burst."
Scottish Liberal Democrat leader Tavish Scott said: "Alex Salmond predicted the SNP would win - he got it spectacularly wrong.
"Scottish politics has changed - the honeymoon is over."
A total of eight candidates contested Glenrothes, in which 36,219 constituents out of a possible 69,155 turned out to vote - 52.3%, compared with 56.1% in the 2005 General Election.
Bookmark with:
What are these?