No campaign supporters react to a declaration in their favour, at the Better Together Campaign headquarters in Glasgow, Scotland. Photograph: Dylan Martinez/Reuters
Scotland stepped back from the brink of ending the 307-year-old union with England and Wales and was on track to remain part of the United Kingdom by a comfortable margin.
With more than half of Scotland's local authorities having declared including the major cities of Glasgow and Aberdeen, an estimated 55% of voters were expected to reject Alex Salmond's prospectus for independence.
But the yes campaign scored a handful of notable successes, succeeding in the largest city of Glasgow by 53% to 47%, winning 54% in West Dunbartonshire and a convincing 57% win in Dundee.
The no camp won victories in their strongholds of East Lothian, Orkney, and Shetland, but also in areas that could have gone to the yes campaign, including Falkirk, Inverclyde, Eilean Siar and Clackmannanshire. Stirling, Renfrewshire, East Renfrewshire, Angus, Dumfries and Galloway and Midlothian also voted no.
Yet that result raises the risk of further turmoil, with Tories in Westminster threatening to revolt against David Cameron's late and potentially vital vow to quickly increase the Scottish parliament's powers while protecting its spending.
David Cameron and the Queen will both move to calm tensions when they deliver statements on Friday. The prime minister will seek early on Friday, in the words of one cabinet minister, to "cement in" the no vote by outlining how he will deliver the deepening of Scotland's devolution settlement, including handing greater powers over tax and welfare, to Holyrood.
The Queen, who has monitored the referendum with interest, will make a written statement on Friday afternoon. It is understood that her remarks will focus on reconciliation.
The prime minister wants to move fast to show that the three main UK party leaders will live up to their commitments made during the referendum campaign to deliver what Gordon Brown called Home Rule within the UK. Ministers believe it is important to move quickly to avoid a repeat of the 1980 referendum in Quebec.
The triumphalist behaviour of Ontario fuelled the separatist cause that nearly succeeded in a second referendum in 1995.
But Michael Gove, the chief whip, made clear that greater protections would have to be offered to protect the interest of English, Welsh and Northern Irish MPs.
Despite the margin of the no campaign's victory, Alex Salmond will now press for a substantial shift in power from Westminster to Holyrood, after the widely praised independence campaign – branded the "greatest in Scottish history" by the first minister, came within only five points of victory.
Salmond, who appeared to realise defeat was imminent by cancelling an expected appearance at his local count, for Aberdeenshire, is poised to demand that Scotland be ceded sweeping tax powers, buoyed by the significant surge in backing for independence.
He watched the first results from television at his home in Strichen, Aberdeenshire, before flying down by private jet from Aberdeen airport to Edinburgh, his disappointment levened only by a substantial yes vote in Dundee, with 57% voting yes.
For the no campaign there was relief: a spate of authoritative polls in the final days of the campaign had said the vote was on a knife edge, bringing Yes Scotland within touching distance of victory after a dramatic surge in support.
Labour's exit polling in 30 out of Scotland's 32 councils suggested they were on course to win by 55% to 45% – a finding that the early results appeared to confirm.
In mid-August, the two campaigns had been 14 points apart – that gap suddenly closed to just six points, to four and then two. No camp strategists were nervous that the very high turnout, which hit 90% in some areas, could give yes a very narrow victory.
One shock poll for YouGov only 10 days before polling had put the yes campaign ahead for the first time, electrifying the contest and stunning the City; the value of sterling fell and more than £2bn was temporarily wiped off the value of Scotland's top seven companies.
An ICM poll for the Guardian put yes on 49% and no on 51% – a result too close to call.
Some 4,283,392 people had registered to vote in the busiest day in Scottish electoral history. Across the board turnouts were high, often well over 80%, although it dropped to 75% in Glasgow.
But it was lower than expected in the pro-independence areas of Dundee at 78.8% and Glasgow at 75% but higher in areas more likely to vote no, including 89.6% in Edinburgh and a predicted very high number in the Borders.
But as the first results and turnout figures were announced, Yes Scotland's hopes began fading fast. The first to declare was Clackmannanshire, a tiny county in central Scotland with under 1% of the electorate but one seen as a political bellwether.
It was expected to vote yes, but went for no, by 54% to 46% – a figure identical to the last opinion poll of the contest, from YouGov published after the polls closed on Thursday night.
And then a spate of smaller councils declared for no: two, the Orkney and Shetland islands, were expected, but the yes campaign had high hopes for the Western Isles, where both the Scottish National party holds both the Holyrood and Westminster seats. In the event, the no vote narrowly won, by 10,545 to 9,195.
By then, it had emerged that the turnout in Glasgow – the largest electorate in Scotland with 486,000 voters was lower than all other councils, at 75%. Dundee, with 118,721 voters, voted as expected heavily for yes but its turnout too was lower than expected, at 78.8%. Both diminished the likely vote for independence across Scotland. West Dunbartonshire became the second to vote yes, with a 5,000 vote margin over no.
Yes campaigners in Glasgow had been confident that their work registering voters disillusioned with Westminster politics, and engaging with those who had never voted before, would bring in the crucial votes they needed to balance more no-leaning areas of the country.
The campaign mounted a huge get-out-the-vote operation on polling day, with people carriers and coaches in some parts of the city. The final turnout seemed the indicate that their efforts had fallen short.