Lib Dem candidate Beatrice Wishart has fought off a strong challenge from the SNP to hold Shetland in a Holyrood by-election.
She succeeds Tavish Scott, who had been MSP for the constituency since 1999 in what was Scotland’s safest seat.
Ms Wishart polled 5,659 votes, ahead of SNP candidate Tom Wills on 3,827, a majority of 1,837.
The Lib Dems saw their majority more than halved from 4,895 in 2016 as the SNP benefitted from a 14.4% swing.
With 11,835 votes cast, the turnout was 66.5%, up from 62% in the 2016 Scottish Parliament election.
Ms Wishart said she was honoured “to make a little bit of history by becoming the first female parliamentarian in Shetland” after a “roller-coaster” campaign.
“Shetland has once again rejected Scottish nationalism and shown that it has not been taken in by the bullying tactics,” she said.
“My work will start on Monday to get the Scottish government to take action on its empty promises for fair ferry funding, to improve nursery provision, mental health care, broadband – the key strands of my positive campaign for Shetland.”
The Holyrood by-election was sparked by the resignation of Mr Scott, who quit politics in July to take a job with Scottish Rugby.
Mr Scott, a former leader of the Scottish Lib Dems, had held the seat since the creation of the Scottish Parliament in 1999.
Beatrice Wishart (Scottish Lib Dems) 5,659 (47.86%, -19.52%)
Tom Wills (SNP) 3,822 (32.32%, +9.27%)
Ryan Thomson (Independent) 1,286 (10.88%)
Brydon Goodlad (Scottish Conservative) 425 (3.59%, -0.07%)
Debra Nicolson (Green) 189 (1.60%)
Johan Adamson (Scottish Labour) 152 (1.29%, -4.61%)
Michael Stout (Independent) 134 (1.13%)
Ian Scott (Independent) 66 (0.56%)
Stuart Martin (UKIP) 60 (0.51%)
Peter Tait (Independent) 31 (0.26%)
14.40% swing Lib Dem to SNP
Electorate 17,810 – Turnout 11,824 (66.39%, up by 4.31%)
Defeated SNP candidate Mr Wills said he gave the Lib Dems “a run for their money in what was the safest seat in Scotland”.
He added: “We take every election seriously and made a point of trying to speak to as many voters in Shetland as possible – and what this extraordinary result shows it that every seat in Scotland is now winnable for the SNP.”
At the last Holyrood election in 2016, Mr Scott won a 44.3% majority over his rivals, the largest by percentage of the vote in Scotland.
The local Westminster seat – Orkney and Shetland – has been held by a Liberal MP of one sort or another for all but 15 of the past 150 years.
The SNP campaigned hard ahead of the vote with First Minister Nicola Sturgeon making several trip to the islands, which lie to the north of the Scottish mainland and have a population of about 23,000.
The party stressed the deep local roots of their candidate, who was born and brought up on the islands – while Ms Wishart is deputy leader of Shetland Council and previously worked in Mr Scott’s constituency office.
Shetland voted 56.5% in favour of Remain in the EU referendum, lower than the 62% across Scotland as a whole, with BBC analysis of local votes finding that one area with particularly strong links to the fishing industry – Whalsay and South Unst – recorded a Leave vote of 81%.
In terms of the other major constitutional issue of the day – Scottish independence – Shetland recorded the fourth-highest No vote in the country in the 2014 referendum, at just shy of 64%.
The Lib Dems accused the SNP of “avoiding the word independence like the plague” in their campaigning, although Ms Sturgeon insisted on a campaign visit that “a vote for the SNP on 29 August is a vote to decide our own future”.