It took three recounts, but just two votes secured victory for the SNP in North East Fife on Friday morning.
Following hours of deliberation and with the promise of further challenges to the result, Stephen Gethins retained his seat with one of the smallest majorities in Scottish electoral history.
He fended off a strong challenge from the Liberal Democrat Elizabeth Riches, with the result eventually being declared at 6.30am.
However, the controversy could only just be beginning, with Mrs Riches’ stating that a legal challenge could be forthcoming.
She said: “We had two winning results for the Lib Dems, we had two winning results for the SNP.
“We think one further recount could have been the answer.
“The returning officer has to use his judgement and he decided not so we will consider what next.”
The first result had placed Riches ahead of her SNP rival by three votes, a lead reduced to just two votes after the first recount.
A second recount placed Mr Gethins ahead by two votes, a result confirmed by the third and ultimately final result.
At one point it is understood that the possibility of locking down the hall and continuing the count later on Friday had been discussed, but utlimately dismissed.
A relieved Mr Gethins said: “I think it’s fair to say it has been an extraordinary night.
“Now I have got a job to do. I’m here to represent everybody in this constituency.
The SNP’s Europe spokesperson added ahead of Brexit negotiations, scheduled to start next week: “Scotland’s voice needs to be hear
Meanwhile, the Conservatives put in another strong performance, adding almost 3,000 votes with its candidate Tony Miklinski.