LONDON — Britain has voted to leave the European Union, a historic decision sure to reshape the nation’s place in the world, rattle the Continent and rock political establishments throughout the West.
Not long after the vote tally was completed, Prime Minister David Cameron, who led the campaign to remain in the bloc, appeared in front of 10 Downing Street on Friday morning to announce that he planned to step down by October, saying the country deserved a leader committed to carrying out the will of the people.
The stunning turn of events was accompanied by a plunge in the financial markets, with the value of the British pound and stock prices plummeting.
The margin of victory startled even proponents of a British exit. The “Leave” campaign won by 52 percent to 48 percent. More than 17.4 million people voted in the referendum on Thursday to sever ties with the European Union, and about 16.1 million to remain in the bloc.
“I will do everything I can as prime minister to steady the ship over the coming weeks and months,” Mr. Cameron said. “But I do not think it would be right for me to try to be the captain that steers our country to its next destination.”
Despite opinion polls before the referendum that showed either side in a position to win, the outcome stunned much of Britain, Europe and the trans-Atlantic alliance, highlighting the power of anti-elite, populist and nationalist sentiment at a time of economic and cultural dislocation.
“Dare to dream that the dawn is breaking on an independent United Kingdom,” Nigel Farage, the leader of the U.K. Independence Party, one of the primary forces behind the push for a referendum on leaving the European Union, told cheering supporters just after 4 a.m.
But it was not clear that the United Kingdom could survive withdrawal from the European Union intact. There was immediate pressure for another referendum on independence from Britain for Scotland, which voted overwhelmingly on Thursday to stay with Europe.
“I think an independence referendum is now highly likely,” said Scotland’s first minister, Nicola Sturgeon, who said it would be “democratically unacceptable” for Scotland to be pushed out of the European Union when a majority of Scots want to stay in.
Keith Vaz, a Labour legislator, said: “This is a crushing decision; this is a terrible day for Britain and a terrible day for Europe. In 1,000 years, I would never have believed that the British people would vote for this.”
European leaders acknowledged that the British vote would further limit their ability to move forward with economic and political integration, a process that had all but stalled anyway.
“Today marks a turning point for Europe,” Chancellor Angela Merkel of Germany said. “It is a turning point for the European unification process.”
In London, the maneuvering began almost immediately to succeed Mr. Cameron, who said he would stay on while his Conservative Party went through the process of settling on a new leader. Among the most prominent of the possible candidates is Boris Johnson, the former mayor of London who was a leader of the Leave campaign. He praised Mr. Cameron as an “extraordinary politician” while saying he was sad to see him go.
Britain will become the first country to leave the 28-member bloc, which has been increasingly weighed down by its failures to deal fully with asuccession of crises, from the financial collapse of 2008 to a resurgent Russia and the huge influx of migrants last year.
It was a remarkable victory for the country’s anti-Europe forces, which not long ago were considered to have little chance of prevailing.
Financial markets, which had been anticipating that Britain would vote to stay in, started plunging before the vote tally was complete, putting pressure on central banks and regulators to take steps to guard against a spread of the damage.
Economists had predicted that a vote to leave the bloc could do substantialdamage to the British economy. Mark Carney, the head of the Bank of England, sought to address those concerns on Friday, saying the bank had made extensive contingency plans and had taken “all the necessary steps” to prepare.
Mr. Cameron had vowed before the vote to move quickly to begin the divorce process if Britain opted to leave. But he said on Friday that he would leave the start of the formal process to his successor, while seeking in the interim to calm the atmosphere before taking any action.
In the meantime, nothing will change immediately on either side of the Channel, with existing trade and immigration rules remaining in place. Thewithdrawal process is expected to be complex and contentious, though under the bloc’s governing treaty it is effectively limited to two years.
Mr. Johnson, like a number of other leaders of the push to leave the European Union, said there was no need to rush to set in motion the legal procedure — invoking a provision known as Article 50 — that would formally sever ties between Britain and the bloc. He and other advocates of leaving the European Union have been taking a go-slow posture on the mechanics of the divorce, saying Britain can get a better deal on trade if it can avoid arbitrary deadlines on the negotiations.
For the European Union, the result is a disaster, raising questions about the direction, cohesion and future of a bloc built on liberal values and shared sovereignty that represents, with NATO, a vital component of Europe’s postwar structure.
Britain is the second-largest economy after Germany in the European Union, a nuclear power with a seat on the United Nations Security Council, an advocate of free-market economics and a close ally of the United States.
The loss of Britain is an enormous blow to the credibility of a bloc already under pressure from slow growth, high unemployment, the migrant crisis, Greece’s debt woes and the conflict in Ukraine.
“The main impact will be massive disorder in the E.U. system for the next two years,” said Thierry de Montbrial, founder and executive chairman of the French Institute of International Relations. “There will be huge political transition costs, on how to solve the British exit, and the risk of a domino effect or bank run from other countries that think of leaving.”
Europe will have to “reorganize itself in a system of different degrees of association,” said Karl Kaiser, a Harvard professor and former director of the German Council on Foreign Relations. “Europe does have an interest in keeping Britain in the single market, if possible, and in an ad hoc security relationship.”
While leaders of the Leave campaign spoke earnestly about sovereignty and the supremacy of Parliament or in honeyed tones about “the bright sunlit uplands” of Britain’s future free of Brussels, it was anxiety about immigration — membership in the European Union means freedom of movement and labor throughout the bloc — that defined and probably swung the campaign.
With net migration to Britain of 330,000 people in 2015, more than half of them from the European Union, Mr. Cameron had no effective response to how he could limit the influx. And there was no question that while the immigrants contributed more to the economy and to tax receipts than they cost, parts of Britain felt that its national identity was under assault and that the influx was putting substantial pressure on schools, health care and housing.
The campaign run by one of the loudest proponents of leaving, the U.K. Independence Party, flirted with xenophobia, nativism and what some of its critics considered racism. But the official, more mainstream Leave campaign also invoked immigration as an issue, and its slogan, “Take control,” resonated with voters who feel that the government is failing to regulate the inflow of people from Europe and beyond.
Other anti-establishment and far-right parties in Europe, like the National Front of Marine Le Pen in France, Geert Wilders’s party in the Netherlands and the Alternative for Germany party will celebrate the outcome. The depth of anti-Europe sentiment could be a key factor in national elections scheduled next year in the other two most important countries of the European Union, France and Germany.
The British campaign featured assertions and allegations tossed around with little regard to the facts. Both sides played to emotion, and the most common emotion played upon was fear.
The “Remain” side, citing scores of experts and elite opinion, warned that leaving the bloc, a so-called Brexit, would mean an economic catastrophe, a plunging pound, higher taxes, more austerity and the loss of jobs.
The Leave side warned that remaining would produce uncontrolled immigration, crime and terrorism, with hordes pouring into Britain from Turkey, a country of 77 million Muslims that borders Syria and Iraq and hopes to join the European Union.
Just a week before the vote, the country was jolted by the brutal murder of a young Labour member of Parliament, Jo Cox, 41, a strong supporter of Remain. A man who prosecutors said shouted “Britain first,” “This is for Britain” and “Keep Britain independent” was charged with her murder.
In England especially, 85 percent of the population of Britain, many people fell back on national pride, cultural exceptionalism and nostalgia. Many English voters chose to believe the insistence of anti-Europe leaders like Mr. Johnson that as a great nation, Britain would be more powerful and successful outside the European Union than inside.
In Scotland and Northern Ireland, by contrast, there was a strong pro-Europe feeling that has only increased tensions within the United Kingdom itself.
Northern Ireland, which has long had an open border with the Republic of Ireland, a member of the European Union, will face a new reality. That open border will become the border between the European Union and a nonmember, and for security and economic reasons it will have to be equipped with border posts to check goods and passports.
Mr. Cameron felt pushed into announcing the referendum in 2013 by the anti-Europe wing of his own party, amplified by concerns among other Tories that U.K. Independence Party and Mr. Farage were cutting too sharply into the Conservative vote.