Image caption Ms Wishart was congratulated by the other nine candidates after the result was announced

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,822, 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,824 votes cast, the turnout was 66.39%, up from 62% in the 2016 Scottish Parliament election. There were 11 rejected ballot papers.

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.

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.

Skip Twitter post by @joswinson Congrats @BeatriceWishart - 1st woman to represent the Northern Isles in any Parliament! Beatrice will be an amazing MSP for Shetland 🧡



Together we'll fight to keep Scotland in the UK & to stop Brexit, because we're better off staying in the EU as a strong family of nations. https://t.co/C9sA9fMJOJ — Jo Swinson (@joswinson) August 30, 2019 Report

Skip Twitter post by @NicolaSturgeon So proud of the outstanding @tprwills and @theSNP #Shetland campaign - our vote share is up almost 10 points and the Lib Dem majority has been slashed, with a 14% swing to SNP. What was the safest seat in Scotland is now a top SNP target for 2021. The #TideIsTurning — Nicola Sturgeon (@NicolaSturgeon) August 30, 2019 Report

The SNP campaigned hard ahead of the vote with First Minister Nicola Sturgeon making three 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.

Much of the debate during the campaign centred on issues including the cost of ferries, poor broadband provision, schools and farming.

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".