The SNP’s Douglas Chapman held on to his Dunfermline and West Fife seat, but with a far closer battle than anticipated.
His majority of 844 votes was a fraction of the 10,352 majority which he swept to victory with in 2015 when he seized the constituency from Labour’s Thomas Docherty.
Friday morning’s result was too close to call until just moments before it was declared at around 2.45am, with Labour’s Cara Hilton looking like she may edge ahead.
At the end of a fraught few hours watching the ballot papers being counted in Glenrothes High School, Mr Chapman said: “We knew we had to push this campaign over the line and it was going to be very, very difficult in light of what’s going on in the country at the moment.
“I’m delighted I have managed to retake this seat.
“We were targeting probably a couple thousand of a majority, I knew it wouldn’t be the majority of 2015 and it’s less than we expected, but nevertheless the win is more important than the majority.”
Ms Hilton used her runner-up speech to call for Theresa May to stand down.
She said: “We’ve certainly got Theresa May running scared. She’s proven she’s not strong and stable, she’s weak and wobbly. It think it’s time she resigned, it’s the honourable thing to do.”
Ms Hacking said the Conservative’s vote in the constituency had quadrupled, with many people backing the party for the first time, fed up with SNP’s focus on independence.
Some 67.5% of Dunfermline and West Fife’s electorate cast their vote, down on the 71.7% turnout of the 2015 general election.
Ms Hilton polled 17,277 votes, Conservative Belinda Hacking 12,593, and Liberal Democrat James Calder 3,019.