The UK was heading for Brexit this morning after huge parts of England and Wales voted to leave the European Union.
Scotland overwhelmingly backed Remain – but it was not enough to keep Britain tied to Brussels.
The result raises the prospect of a second independence referendum north of the border.
It will also prompt questions of Labour, which campaigned for In, after many of the party’s heartlands in northern England voted for Out.
An emotional Prime Minister David Cameron announced that he would step down in three months as the country enters negotiations to leave the UK.
Ukip Leader Nigel Farage delivered an emphatic victory speech, despite having said earlier that Remain would “edge it”.
He said June 23 would “go down in history as our independence day” and that he hoped the win would bring down the entire “failed project” that is the EU.
The final vote was 17,410,742 to 16,141,241 for remain, or 51.9% to 48.1%.
Every single voting area in Scotland supported the UK’s continued membership of the EU.
In total, 1,661,191 backed Remain with 1,018,322 voting for Leave.
Just over two thirds (67.2%) of eligible voters took part in the poll, with a total of 2,681,179 votes cast north of the border.
The turnout compares with 55.6% in the recent Scottish Parliament election and 84.5% in the 2014 independence referendum.
Across the UK it was higher, at 72.2%, based on a confirmed electorate of 46,500,001.
During the campaign, the SNP leader argued a vote to stay in the EU in Scotland but a Brexit win overall could constitute the “material change” of circumstances required to trigger a second independence referendum.
Orkney was the first of Scotland’s 32 local authorities to declare, with almost two-thirds of the votes going to Remain.
South of the border, large parts of London backed Remain, but in Essex, Kent and the north-east of England, as well as many areas on the periphery of the capital, the Brexit voice won out.
Mr Cameron had stressed again and again that the UK was “stronger, safer and better off” inside the EU.
He – and pro-Remainers from across the political spectrum – also warned of the potentially severe economic consequences of a Brexit vote amid fears of financial market turmoil and another recession.
But Leave campaigners urged voters to “take back control” of the country.
They argued a Brexit would give the UK more money to spend on things like the NHS and enable the UK Government to manage immigration levels.