Here are where some of the main battles were fought.
SNP newcomer Siobhian Brown snatched this one-time Tory stronghold from veteran MSP and former deputy presiding officer John Scott by just 170 votes.
The figures suggest Mr Scott held onto most of the Tory vote while there was a slight shift of support from Labour to the SNP.
However, some Tories are said to believe the party made a mistake in focusing too much on the regional lists, urging people to back the Conservatives on the peach ballot paper whatever they did with their constituency vote, and failed to put enough money and effort into holding onto its vulnerable constituencies.
It was never going to be easy for the Tories to hold the seat in the heart of the Capital where former leader Ruth Davidson scored a dramatic surprise victory in 2016.
But Angus Robertson’s victory for the SNP, with a majority approaching 5,000, was evidence that tactical voting by anti-independence supporters in a bid to block the Nationalists did not always work.
In contrast, tactical voting did help Labour and the Lib Dems to retain Edinburgh Southern and Edinburgh Western in the face of SNP challenges.
The SNP’s victory in a seat which Labour had held since the start of the Scottish Parliament showed the Nationalists had not reached the limit of their appeal to traditional Labour voters. Paul McLennan’s victory in the constituency being vacated by former Scottish Labour leader Iain Gray saw a swing of around 2.7 per cent from Labour to the SNP. But there were some suggestions the Tories might have helped the pro-union cause if they had not put so much effort into their campaign.
In contrast, Labour’s deputy leader Jackie Baillie survived a determined SNP campaign to unseat her in Scotland’s most marginal constituency. Along with Daniel Johnson’s return in Edinburgh Southern it was good news for Labour when the party seemed to be getting squeezed between the SNP and Tories over the constitutional issue. In both cases there was evidence of voters who would normally back the Tories switching to Labour as the best bet to beat the Nationalists.
Galloway and West Dumfries
The Tories’ Finlay Carson held on with an increased majority in this seat which the SNP had targeted. Some of it was thanks to Labour voters switching to support him, though the figures suggest there were also many Labour supporters who switched to the Greens.
Perthshire South and Kinross-shire
The SNP managed to hang onto the seat which veteran Nationalist Roseanna Cunningham had held since the start of the Scottish Parliament despite her narrow 1,422 majority over the Tories last time. Jim Fairlie’s success in seeing off the challenge from the Tories’ Liz Smith by a slightly increased margin emphasised the Nationalists’ ability to do well in rural seats which might traditionally be seen as Tory territory as well as in urban former Labour areas.