Nicola Sturgeon‘s party had mounted a strong campaign in the election, which was sparked by the resignation of former Scottish Liberal Democrat leader Tavish Scott.
The First Minister made several visits to the island in the lead up to the election.
SNP candidate Tom Wills won 3,822 votes, with a 14.4% swing from the Lib Dems to the SNP.
But Beatrice Wishart took 5,659 votes, 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 “roller coaster” 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.
Unsuccessful candidate Mr Wills said that he was encouraged by the increase in the SNP.
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.”
He added: “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.”