By Angie Brown
BBC Scotland news website
Edinburgh and East reporter
The cheers for Willie Rennie almost raised the roof as he was declared the victor in the Dunfermline and West Fife by-election.
It was an historic night for an ecstatic Willie Rennie
It was an extremely tense but exciting finale following weeks of campaigning to find a successor to the late Labour MP Rachel Squire.
Ms Squire had been so highly regarded during her long-standing reign as MP for the area that the candidates knew she would be a hard act to follow.
Labour was defending a majority of more than 11,500 from the General Election - a formidable challenge for the party's opponents.
Whisperings of a "political earthquake" had begun at the count in the packed hall at Queen Anne High School in Dunfermline before midnight on Thursday.
However, it wasn't until the returning officer made the announcement that onlookers started showing their amazement.
As the winner was announced just before 0045 GMT on Friday morning, many people seemed to hold their breath.
Labour's Catherine Stihler had lost her fight to save the Labour seat.
At first things moved slowly following the close of polling stations at 2200 GMT.
Most people gathered for the count at the school in Broomhead Parks thought Labour would hold onto the seat and that it was all about the race for second place between the SNP and the Liberal Democrats.
Agents watched the counters intently as piles of ballot papers began to grow.
Candidates passed the time with journalists as they waited behind a yellow taped cordon for the result. There was idle and friendly chat.
Catherine Stihler was thwarted in her bid to succeed Rachel Squire
When it became evident that the race was actually neck and neck between Labour and the Liberal Democrats, politicians began to openly admit that they were nervous and tense.
In the aftermath of the shock Labour defeat, many of the other eight candidates hailed Willie Rennie for an "historic victory".
He started his speech by paying tribute to "my Scottish leader Nicol Stephen", who he said had given him fantastic support.
He also added that it must have been a "deeply depressing night for the SNP" who came third.
It wasn't to be the SNP's night, despite the by-election being hosted in the town where the great Scot Robert the Bruce was buried.
However, for Willie Rennie it was a night for making history, taking what had been a safe Labour seat.