The Liberal Democrats have won the Shetland by-election, holding on to the seat despite the SNP returning a record number of votes in the island constituency.

Nicola Sturgeon's party mounted a strong campaign in the election, which was sparked by the resignation of former Scottish Liberal Democrat leader Tavish Scott, with the First Minister making several visits.

SNP candidate Tom Wills won 3822 votes, with a 14.4% swing from the Lib Dems to the SNP.

Beatrice Wishart took 5659 votes, however, making history by becoming the first female parliamentarian elected to represent the area.

Ms Wishart said she was honoured to "to make a little bit of history by becoming the first female parliamentarian in Shetland" after the "rollercoaster" campaign.

She added: "Shetland has once again rejected Scottish nationalism and shown that it has not been taken in by the bullying tactics.

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

Alistair Carmichael, the Liberal Democrat MP for Orkney and Shetland, said Ms Wishart had fought a "fantastic campaign".

"There's no doubt she will be a first-rate member of the Scottish Parliament for Shetland," he added.

"This must be a bitter disappointment for the Scottish nationalists. Just last week Nicola Sturgeon was here for her third visit in a month, telling us it was going to be neck and neck.

"If that was neck and neck, all I can say is that's some neck."

The former Scottish Secretary added: "I think people in Shetland were threatened by the SNP, they sought to misrepresent the fantastic work that Tavish Scott did for Shetland over 20 years, and I think they have frankly had a pretty harsh judgement."

Mr Scott, who stood down from Holyrood to take up a new post with Scottish Rugby, had held the Shetland constituency for the Liberal Democrats since the Scottish Parliament was created in 1999.

SNP candidate Mr Wills said that he was encouraged by the increase in his party's vote share.

He said: "In a matter of weeks we have taken Shetland from being Scotland's safest seat to one of the SNP's top targets in 2021. It's a truly remarkable achievement and we are all determined to build on this result over the next 18 months.

"We've achieved our best ever result in Shetland and the increase in our vote is hugely encouraging - after 12 years in government, we have given the Lib Dems a run for their money in the what was the safest seat in Scotland.

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

Independent candidate Ryan Thomson came in third, with 1286 votes, ahead of Conservative Brydon Goodlad on 425, Green candidate Debra Nicolson on 189 and Labour's Johan Adamson on 152.

Independent candidate Michael Stout polled 134 votes, with Ian Scott collecting 66, while UKIP candidate Stuart Martin secured 60 votes and independent Peter Tait picked up 31.