Scotland eventually voted quite heavily in favour of remaining in the EU. But England and Wales voted against.
As a result, Scotland is at risk of being taken out of the EU against the will of a majority of its people – unless, perhaps, it can secure its independence before the UK does leave.
For nationalists being in the EU is a way in which Scotland can realise its sovereignty, rather than, as many in England consider it, as an unacceptable curb. And while a minority of SNP voters were not willing to follow the party line on the EU, that stance was enough to ensure Scotland voted heavily in favour of Remain.
But surprise or not, the overall UK result leaves Nicola Sturgeon with a headache as she seeks to reflect the undoubted anger that many SNP supporters feel at the prospect of Scotland’s will being overturned by England. However, there are three key hurdles to be overcome before a second independence referendum is likely.
First, it will need to be clear that the result has not just affronted nationalists but also those who hitherto have been of a unionist persuasion. Polling during the referendum campaign suggested there might be a four or five point swing in favour of independence should the UK vote for Brexit. That would be enough to put support for independence above 50 per cent, but it would be insufficient to take it anywhere close to the 60 per cent mark Nicola Sturgeon has said she would want to see before she would risk a second contest.
But even if there was a big swing in favour of independence, Ms Sturgeon would still need to be able to pass the legislation needed to hold a referendum. That means, on the one hand, securing the support of the Greens at Holyrood and, on the other, finding a form of words for the referendum question that would not be struck down in the courts. Neither outcome is guaranteed.
However, the most important uncertainty of all will be how the EU itself might react to the prospect of an attempt by Scotland to seek its independence in order to secure its place inside the EU. There would be little point in holding an independence referendum if the EU were to indicate that Scotland was heading for the exit door anyway.
But what if the EU decided that if part of the UK wishes to leave and part to stay, the latter should be regarded as a continuing member of the Union? Then it might be game on.
• John Curtice is Professor of Politics, Strathclyde University