Britons voted to leave the European Union in a startling rebuke that rattled financial markets and threatens to spark political turmoil in the U.K. and weaken a continent already strained by multiple crises.
With all voting areas counted, Leave beat Remain 51.9% to 48.1% early Friday, severing the U.K.'s ties with the EU after 43 years.
The pound fell more than 10% to its lowest point since 1985 and the outcome triggered steep drops in stock markets and a flight into safe assets such as bonds and gold.
The result instantly reshapes the political legacy of U.K. Prime Minister David Cameron, who led the "remain" effort, and imperils his job as prime minister. Whoever leads the U.K. will face the challenge of uniting a country that is now openly, and roughly evenly, divided over its relationship with Europe.
It also raises questions about the future shape of the U.K., with the results showing a split between voters in Scotland, which largely voted in favor of continued EU membership, and those in other parts of the country. Ahead of the vote, First Minister Nicola Sturgeon signaled that the Scottish National Party would push again for secession if Britain chose to leave the EU.
Mr. Cameron tried to focus voters on what he said were huge economic and security risks that would accompany leaving the EU. But the campaign was increasingly dominated by a sharp and emotional discussion of immigration and Britain's national identity.
As votes rolled in, a portrait of a deeply polarized nation came into focus. The results pitted London and Scotland, where Remain was strong, against most of the rest of the country.
"It's a small country and we're getting overrun," said Chris Matthews, a 56-year-old Wales resident, reflecting a common Leave camp view that the U.K. had allowed excessive immigration. "They don't speak the language." Mr. Matthews cast his leave ballot in Wales on Thursday morning and spoke on a train to Sunderland.
Nigel Farage, leader of the UK Independence Party and a key figure in the pro-Brexit camp, said the referendum campaign had transformed British politics, catapulting so-called euroskepticism into the mainstream.
"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...Let June 23 go down in history as our independence day," he said.
The EU will face an epic gut-check over its purpose and future. The decision will top the agenda at a meeting of European and foreign affairs ministers in Luxembourg in the afternoon.
Britain's exit costs the body one of its wealthiest members and one of its biggest military powers. The EU is weighed down with economic and migration crises and turmoil in the nearby Middle East and Russian aggression.
European Parliament President Martin Schulz said he had already spoken with French president Francois Hollande and will speak with German Chancellor Angela Merkel shortly to discuss ways to prevent a "chain reaction" across the EU.
"It will be a difficult road without Great Britain," Mr. Schulz said. "We now have to look together with our partners in the world and inside the EU how we tackle this."
Now, the EU faces the possibility that similar euroskeptic forces across the region will come to life and prompt other members to attempt an exit. Marine Le Pen, the head of France's anti-immigration National Front, called for a referendum on membership, while Geert Wilders, the leader of the euroskeptic Dutch Freedom Party, welcomed the U.K. result, saying on Twitter that "the Netherlands will be next!"
Mr. Cameron staked his political future on the referendum. As leader of the campaign to persuade Britons to remain in the EU, he will likely face immediate pressure to resign.
The outcome will be a disappointment for the many in Britain who had voted to remain in the 28-member bloc, driven by concerns of the risks of involved in leaving. Among the many major unknowns is what the U.K.'s trade relationships, not only with Europe but also other parts of the world, will look like and what happens to the many British citizens living elsewhere in Europe as well as the many EU citizens in the U.K.
The uncertainty battered the British pound by more than 11% Thursday night and into Friday morning. Trading in stocks and currencies over the past week had implied investors were increasingly confident that Britain would remain in the EU.
Thursday's nail-biting vote count set off a wild ride in the markets. Early predictions that Remain would win were followed by initial returns showing stronger-than-expected results for the Leave camp in key areas of northeast England. That sent the pound on a roller-coaster ride, with the currency touching highs and lows for the year against the dollar.
As the first results started rolling in, the northeast port city of Sunderland, home to the U.K.'s largest auto plant and generally supportive of the main opposition Labour Party, saw a stronger-than-expected support for leaving.
The announcement there sparked a rousing cheer on the floor of the convention center where the ballots were counted among those leaning Leave.
"Leave appear to have tapped a deeper reservoir of traditional Labour voters than we might have previously assumed," said Pawel Swidlicki, a policy analyst at Open Europe, a think tank.
Turnout was expected to be an important factor in the result, with many analysts having predicted a high turnout would benefit the Remain camp. But heavy rains swept across southeast England, including London, a stronghold of pro-EU support, and turnout was lower than expected in pro-Remain Scotland.
"I never normally vote in a general election because they're all as bad as each other, but I wasn't going to miss this one," said Kim Flemming, a 52-year-old unemployed mother of two in South London who said she voted to leave the EU because she thought the U.K. should have more control over its borders.
Friday's result is the culmination of an at times vitriolic monthslong campaign that pitted the prime minister against other senior figures in his center-right Conservative Party, with both sides accusing the other of misleading the public. The campaign was put on pause last week following the brutal killing of British lawmaker and active pro-EU campaigner Jo Cox, who was stabbed and shot in the street in broad daylight.
The debate laid bare the high levels of anti-EU sentiment and distrust of the political establishment among some in the U.K., expressing a frustration with the status quo that has similarities to the forces fueling support for Donald Trump in the U.S. and populist parties elsewhere in Europe.
While opinion polls had suggested a close-fought race up until the eve of the vote, the British public appears ultimately to have been swayed by arguments from the pro-exit campaigners that Britain faced a brighter future untethered to a Continent that faced increasing challenges.
Immigration became a key issue in the debate amid concerns among some Britons that the government seemed unable to reduce the numbers of EU citizens coming to the U.K. Membership in the bloc ensures the free movement of people between member states.
The result came despite Mr. Cameron's persistent warnings of the economic and security risks of leaving--a strategy his opponents dubbed "Project Fear." The prime minister had argued that leaving the EU would trigger a sharp decline in the U.K. economy--what he referred to as the world's first "DIY recession"--leading to fewer jobs, lower wages and higher prices.
That message resonated with some. James Townley, a 37-years old Londoner, said he was conflicted about his vote until about 10 days earlier. The business-development associate said if the vote was reversed and the U.K. was deciding whether to join the EU today, he wouldn't be in favor. But remaining a part of the continental bloc, he ultimately decided, is important to the nation's prosperity.
Mr. Townley said there is a "fear of the unknown."
In the final days of campaigning, Mr. Cameron crisscrossed the country in an effort to persuade voters. In a last-ditch appeal on Wednesday, he promised to press Brussels for further overhauls. But he was quickly undercut by European Commission President Jean-Claude Juncker, who said Britain had already won the maximum concessions it could.
Katie Riordan and Scott Patterson contributed to this article.
Write to Jenny Gross at email@example.com