Britain has voted to leave the European Union in a historic referendum result that exposed deep divisions in the country and led to David Cameron announcing his resignation as prime minister.
The victory for the Leave campaign, which flew in the face of opinion polls that suggested a narrow win for Remain, overturns 40 years of British membership of the European project and sent the currency markets into immediate panic, with the pound plummeting to its lowest level since 1985.
While Scotland and London voted for Remain, anti-EU voters turned out in larger numbers across large swaths of England and Wales to reject the pleas of Cameron and the other main party leaders to stick with the EU. The only party leader to back Brexit was UKIP's Nigel Farage.
The result is an enormous personal defeat for Cameron, who called the referendum to head off Eurosceptics in his own party and counter the rise of UKIP. After claiming to have won a series of reforms from the EU, he gambled his premiership on winning the vote for Remain. Outside Downing Street this morning he gave an emotional address confirming that the gamble had backfired.
"The British people have made a very clear decision to take a different path, and as such I think the country needs fresh leadership to take it in this direction. I will do everything I can as prime minister to steady the ship over the coming weeks and months," Cameron said, adding he expected a new prime minister in office by October.
“This is not a decision I’ve taken lightly, but I do believe it is in the national interest to have a period of stability and then the new leadership required.”
By 4am on Friday Brexit was all-but confirmed, as first ITV News then the BBC and Sky News declared that Leave had won by a projected 52% of the vote to Remain's 48%. The final officially tally was 17,410,742 votes for Leave, and 16,141,241 for Remain. Turnout was 72%.
The official Vote Leave campaign was led by Conservative MP and former London mayor Boris Johnson, who will now be frontrunner to succeed Cameron, while Farage ran his own unofficial campaign. The anti-EU campaigners focused heavily on the issue of cutting levels of immigration and attacked the perceived elitism of the Remain campaign. In the process they celebrated an unexpected victory.
"I now dare to dream that the dawn is coming up on an independent United Kingdom," said Farage a party in central London. "This will be a victory for real people, a victory for ordinary people, a victory for decent people."
The veteran anti-EU politician appeared close to tears as he predicted the vote would prompt the downfall of the entire EU by encouraging other countries to quit: "I hope this victory brings down this failed project and leads us to a Europe of sovereign nation states trading together, being friends together, cooperating together. And let's get rid of the flag, the anthem, Brussels, and all that's gone wrong."
The decision to vote for Leave caused the value of the pound to crash against the dollar as currency markets hammered the UK for backing Brexit, and stock markets are expected to be hit hard when they open.
Leave surpassed expectations in almost every area of the UK and secured a substantial margin of victory in most parts of the UK, including in traditional Labour heartlands in Wales and the north of England.
The Remain campaign had to console itself with strong victories in some major cities such as London and Liverpool and a strong performance in most of Scotland.
Labour sources are now calling on the prime minister to consider resigning, while Jeremy Corbyn's party faces its own inquest after many of its traditional voters ignored its pro-EU message and chose to vote for Brexit.
Speaking to BBC News in Westminster, Corbyn called on article 50, which triggers Britain's formal exit from the EU, to be invoked immediately.
He said the result was largely down to the government's austerity policies.
"I think a lot of the message that has come back is that many communities are fed up with cuts, fed up with economic dislocation, and feel very angry at the way they've been betrayed and marginalised by successive governments in very poor areas of the country," the Labour leader said.
Pro-Brexit Conservative MP Jacob Rees-Mogg suggested there could now be a new general election well before the expected 2020 date, while Farage called for a "Brexit government".
But Corbyn stopped short of calling for a general election or for Cameron to resign.
Donald Tusk, president of the European Council, said there would be no "legal vacuum" for the UK following the vote. "We are determined to keep our unity as 27," he said in a statement, adding: "What doesn't kill you makes you stronger."
SNP politicians said the vote to leave the EU would reopen the issue of Scottish independence, since they would not allow Scotland to be taken out of the EU against its will.
In a statement after the result had been called by the three main broadcasters, Scotland’s first minister, Nicola Sturgeon, said: “Scotland has delivered a strong, unequivocal vote to remain in the EU, and I welcome that endorsement of our European status.
“And while the overall result remains to be declared, the vote here makes clear that the people of Scotland see their future as part of the European Union."
She added: “We await the final UK-wide result, but Scotland has spoken – and spoken decisively.”
Turnout was substantially higher than expected, beating the level seen in the 2015 general election.
The result follows a vicious referendum campaign that saw the UK government, the leaders of Britain's main political parties, world leaders such as US president Barack Obama, the majority of British businesses, and the vast majority of expert opinion back the Remain campaign.
By contrast, the Leave campaign was divided into rival factions and only attracted the support of UKIP and a handful of prominent Conservative ministers such as Johnson and justice secretary Michael Gove.
Leave gained ground in the final fortnight, but campaigning was halted following the shooting of Labour MP Jo Cox. When campaigning resumed, it was with a more muted tone and polls suggested some voters had returned to Remain.
As a result, the pro-EU side started the night very confident of a narrow victory, with UKIP leader Nigel Farage all but accepting defeat as polls closed and pollsters YouGov projecting a 52% win for Remain.
But early results from the North East of England showed better-than-expected results for the pro-Brexit option, resulting in market jitters.
Throughout the night, Leave continued to outperform expectations, consistently racking up more votes than forecast even in areas won by Remain. By dawn it was clear the UK had voted to leave the EU and British politics had been fundamentally altered.
Jim Waterson is a politics editor for BuzzFeed News and is based in London.
Contact Jim Waterson at email@example.com.
Got a confidential tip? Submit it here.