Lesley Laird will now take over as the area’s MP, after narrowly defeating Roger Mullin, who was elected in 2015.
She pulled in 17,016 votes, as Mr Mullin got 16,757.
Speaking after her victory, Ms Laird said: “In an election where just a few weeks ago Labour not given a chance, this is a indeed a remarkable result.
“At a rally a few weeks ago I asked supporters what it would feel like to hear Labour had won. It feel even sweeter to hear it for real
“I thank the hard work if my campaign team, especially my agent and good friend David Ross.
And to Gordon Brown ... this one us for you.”
Mr Mullin said: “I am of course disappointed, but I have to say I think in the morning I will still be able to lok at myself in the mirror and know for the last two years I did all I could to serve the good people of this constituency.”
Dave Dempsey of the Conservatives came in third place with 10,762, Malcolm Wood of the Lib Dems had 1118, while Ukip’s David Coburn had 540.
Speaking before the result, Mr Mullin said that Theresa May could have written the longest suicide note in history.
Mr Mullin said of the battle for the Fife seats: “We knew from our sampling that it would be competitive in all three constituencies.
“On the doorsteps we found people that have seemed well motivated to vote but in a genuine quandary about the situation that they are faced with.
“I think that everybody thought that it was a foregone conclusion landslide victory for the Tories, but the dynamic changed when Theresa May must have run the worst campaign ever from a sitting Prime Minister.
“It was said that in the early 80s Michael Foot wrote the longest suicide note in history, well maybe it wasn’t so long as this one!
“If the exit poll for the UK is correct and she thrown away a 20 point lead, she’s absolutely dead in the water.”
Meanwhile, the Conservative candidate in Kirkcaldy, Dave Dempsey, was optimistic.
“Voters now understand and accept what the Conservative party stands for,” he said. “More and more are supporting our clear stance on the protection of the Union and our opposition to a second independence referendum.
“I’ve campaigned as a Conservative in Fife for 17 years and have never seen the type if support that I have experienced in the last year
“Our policies resonate with more and more voters than I’ve ever experienced before in the doorsteps
“Success at recent council election has continued into this campaign and given us something solid to build on
“We don’t expect to win this seat I’ve nothing to lose but we will secure a solid third place and or message and values are attracting voters that just a few years ago would not have looked at us because of our image with voters in the last.”
Ukip candidate David Coburn said: “I stood in this seat because the likes of Roger Mullin and Gordon Brown before him have neglected local issues.
“First and foremost people in Kirkcaldy and Cowdenbeath want jobs and they deserve better representation than they have been getting.”
Asked about his party’s slump as the percentage of the vote collapses across the UK, Mr Coburn remained bullish reminding us that Ukip remain the largest party in the Euro parliament
“We won that election and its vital that we did as we will play a huge part in ensuring the UK gets he best outcome from Brexit negotiation
“The Tories would have no meaningful policies had it not been for Ukip and there is obviously no appetite for a second independence referendum in Scotland.
“I think that lack of desire for a independence will actually signal the beginning of the end for SNP in the long term.”