The SNP has held the Fife North East seat with just two votes.
It was the final Scottish seat to declare in the UK general election, after a third recount.
The SNP’s Stephen Gethins won 13,743 votes while Elizabeth Riches of the Scottish Liberal Democrats polled 13,741.
It is the joint-third narrowest victory in UK general election history and the closest since the Lib Dem’s Mark Oaten won Winchester by two in 1997.
Mr Gethins saw his majority cut from 4,344 in 2015.
The result joins a handful of general election results which exercise the minds of psephologists.
Close calls – the narrowest general election wins
In 1886 the narrowest recorded majority in a British general election was just zero – a record held by John Edmund Wentworth Addison, the Conservative candidate for Ashton-under-Lyne, now part of Greater Manchester.
He drew with his Liberal Party opponent but, under different electoral rules, became MP on the casting vote of the local mayor in his role as returning officer.
Addison held the seat at the 1892 election and stood down from parliament in 1895.
In 1910, Conservative candidate Henry Duke won by just one vote in Exeter while Abraham Flint, standing for National Labour in Ilkeston, Derbyshire, in 1931 won by two votes.
Among the smallest majorities recorded since 1945, is the 1974 win for the SNP by a young Margaret Bain, later Ewing, who took East Dunbartonshire from the Conservatives.
She won by just 22 votes – but this general election saw it surpassed by an even narrower win when the SNP’s Pete Wishart saw his near 10,000 majority slashed to just 21 in Perth and North Perthshire.
Please include a contact number if you are willing to speak to a BBC journalist. You can also contact us in the following ways: