The United Kingdom has voted to leave the European Union. Votes are still being counted, but the BBC, the Guardian, and other media outlets have projected a win for the "Leave" campaign.

The result is a surprise — betting markets had been projecting an 80 percent chance of a "Remain" victory as late as this afternoon — that could mean big changes for the British people and foreigners living in Britain.

The next few weeks will see a flurry of activity on both sides of the English Channel. The Leave campaign’s win is an embarrassment for Prime Minister David Cameron, who campaigned to stay in the EU, and it may set off a power struggle for leadership of his Conservative Party.

British and European leaders must now begin a long and painstaking process to negotiate the terms of Britain’s future relationship with the EU. And EU leaders will have to consider reforms to dissuade other EU members from following Britain’s lead.

Britain’s exit will also have huge implications for the British economy. We can expect the British stock market and the value of the British pound to open sharply lower, and some pessimists even expect Britain to fall into recession. In the long run, most economists believe the British economy will be smaller without the EU than it would be if Britain stayed in, but there’s disagreement about the size of the effect.

The Brexit vote is the start of a years-long negotiation

The Brexit vote is not legally binding, and there are a few ways that it could theoretically be blocked or overturned. However, as the BBC notes, "it would be seen as political suicide to go against the will of the people as expressed in a referendum."

Article 50 of the Treaty on European Union establishes the procedures for a member state to withdraw from the EU. It requires the member state to notify the EU of its withdrawal and obliges the EU to then try to negotiate a withdrawal agreement with that state.

A Brexit vote, however, does not represent that formal notification. That notification could take place within days — for example, when EU member countries meet for a summit that is scheduled for June 28 to 29. Or British officials might wait a few months to pull the trigger.

Once Britain invokes Article 50, it will have a two-year window in which to negotiate a new treaty to replace the terms of EU membership. Britain and EU leaders would have to hash out issues like trade tariffs, migration, and the regulation of everything from cars to agriculture.

In the best-case scenario, Britain may be able to negotiate access to the European market that isn’t that different from what it has now. Norway is not a member of the EU, but it has agreed to abide by a number of EU rules in exchange for favorable access to the European Common Market.

But there’s also a risk that EU and British leaders won’t see eye to eye. The EU may decide to strike a hard bargain to discourage other countries from leaving the EU. Or the UK might not be willing to accept the kind of restrictions that come with a Norway-style deal.

The vote could topple the British government

British Prime Minister David Cameron didn’t want to hold a vote on Brexit at all. But in 2014, he faced growing pressure from the populist right over immigration and Britain’s EU membership. To mollify dissenters in his own party and stop the rise of the far-right UK Independence Party, Cameron promised to hold a referendum on leaving the EU if his Conservative Party won the 2015 election.

The Conservatives surprised pollsters by winning an outright majority in Parliament, and Cameron kept his promise. But he wasn’t personally in favor of exiting the EU, and he campaigned vigorously for a Remain vote. At the same time, he allowed other members of his government to campaign on the other side. This created the spectacle of senior members of the UK government, from the same party, campaigning on opposite sides of one of the biggest issues in British politics in decades.

The victory of the Leave campaign could fatally weaken Cameron’s standing within his own party. Cameron had vowed to continue in office even if voters rejected his stance on EU membership. But that position may prove untenable. A revolt among Conservative members of Parliament could force Cameron out of office. That could lead to a new Conservative government run by a more Euroskeptical prime minister, or it could lead to new elections.

Exiting the EU will have a big impact on the British economy

In recent decades, the EU has made great progress in dismantling trade barriers among member countries, allowing the EU to function as a single integrated economy much like the United States. Britain’s exit from the EU will require a wrenching reversal of those reforms, forcing people moving goods or themselves across the English Channel to once again worry about different legal regimes in Britain and on the continent.

"If you are Nissan or some other car producer with major production in the UK, today, the same safety standards and environmental standards allow you to sell everywhere in the European market," said Jacob Funk Kirkegaard, an economist at the Peterson Institute for International Economics, in an interview last week.

But once the UK leaves the EU, "you will no longer be able to sell into other European markets, not because you face a small tariff, but because you'd have to go through another set of safety certifications. This kind of thing would be repeated in every industry you can think of."

An area of particular concern is the financial sector. London is the de facto financial capital of Europe. A London bank can provide seamless financial services from Poland to Portugal. And this fact — along with the fact that English is spoken around the world — has attracted business from companies around the world.

But with Britain out of the EU, companies may find it makes more sense to handle their European business separately from their British operations. Companies that have headquartered their European operations in the UK may move some personnel to another European capital, costing Britain jobs and tax revenue.

In the short run, uncertainty about Britain’s future relationship with the EU, its largest trading partner, could push the UK into a recession. Market watchers predict an "explosion of volatility" on Friday morning as the markets process the implications of Britain’s exit. Many economists expect both the British stock market and the pound to open lower on Friday morning. Britain’s chancellor of the exchequer, George Osborne, even hinted that he could suspend stock market trading if Britons voted to exit the EU.

In the long run, most economists believe that Britain’s exit will take a few percentage points off the size of Britain’s economy. The UK government has estimated that exiting the EU could cause the British economy to be between 3.8 and 7.5 percent smaller by 2030 — depending on whether the government can negotiate a favorable trade deal with the EU. Other economists suggest the effect will be smaller but still significant.

Brexit means significant uncertainty for migrants

One of the most important and controversial achievements of the EU was the establishment of the principle of free movement among EU countries. A citizen of one EU country has an unfettered right to live and work anywhere in the EU. Both Britons and foreigners have taken advantage of this opportunity.

There currently are about 1.2 million Brits living in other EU countries, while about 3 million non-British EU nationals live in Britain. Thanks to EU rules, they were able to move across the English Channel with a minimum of paperwork. Britain’s exit from the EU could change that profoundly.

It’s possible, of course, that Britain could negotiate a new treaty with the EU that continues to allow free movement between the UK and the EU. But resentment of EU immigrants — especially from poorer, economically struggling countries like Poland and Lithuania — was a key force driving support for Brexit. So the British government will be under immense pressure to refuse to continue the current arrangement.

At a minimum, that would mean that people moving to or from Britain would need to worry about passports and residency rules. And it could mean that some British immigrants may lose their right to continue living and working in the UK and be deported.

"The withdrawal process is unprecedented," a British government spokesperson said a few weeks ago. "There is a great deal of uncertainty about how it would work."

Brexit is a wake-up call for the EU

The loss of one of the EU’s largest and wealthiest members is going to prompt some serious soul-searching among the EU’s leaders.

Many economists believe that the EU made a big mistake when it created its common currency, the euro, in the late 1990s. Economic research suggests that the euro — and mismanagement by the European Central Bank — worsened the aftermath of the 2008 financial crisis. It created an economic depression in countries like Greece and Spain that continues to this day.

In the United States, federal spending helps smooth out economic difference between the states. If California is booming and Michigan is in a slump, the federal government uses tax revenue from Silicon Valley millionaires to pay unemployment and Social Security benefits for people in Michigan.

But the EU doesn’t have anything like this. The EU doesn’t have an independent power to collect taxes, and social spending happens at the level of national governments. That means governments hardest hit by recessions — like Greece, Spain, and Italy after 2008 — get hit by declining tax revenues at the same time that demand for welfare benefits soars. The effect is to magnify the intensity of recessions — which is why the unemployment rates in Greece and Spain are still above 20 percent.

So Britain’s exit could wind up being useful in two ways. First, it could be the shock that forces the EU’s other 27 members to get serious about the ambitious reforms that will be required for the EU to operate as a single, integrated economy.

Second, Britain was one of just two EU countries that refused to join the euro (Denmark is the other). Inside the EU but outside the euro, Britain would have felt less urgency about deeper economic integration, and so could have become a key obstacle to reform. With Britain gone, it may be easier to corral the rest of the EU into a closer union.

But it might still be too difficult. The same populist forces that are pushing Brexit out of the EU are also at work in other EU countries. We don’t know which country will consider exiting the EU next, but Britain’s referendum is unlikely to be the last the EU will see. So Brexit could lead to a more integrated EU, or it could be the first step in its slow disintegration.

Watch: How the euro caused the Greek crisis