LONDON — Britain has voted to leave the European Union in a historic referendum that forced the country's prime minister to step down, upended markets and set the stage for a messy untangling with far-reaching implications.
Electoral officials said early Friday that the "Leave" campaign had racked up 17.4 million votes — compared to 16.1 million backing the status quo. That gave "Leave" 51.9 percent of the ballots against 48.1 percent for "Remain," capping a deeply divisive campaign.
The vote served as an indictment of Britain's government and a barometer of domestic fears about immigration and the economy.
Prime Minister David Cameron — who had forcefully campaigned to stay in the EU — later announced he would step down, saying the country needed fresh leadership.
"I do not think it would be right for me to be the captain that steers our country to its next destination," he told reporters outside his Downing Street office.
The vote for an exit — or Brexit — has sent shockwaves through global markets. The pound plunged to $1.35, its lowest level since 1985.
The EU now finds itself in uncharted waters: No nation state has ever left the bloc. The leaders of the EU institutions urged Britain to act quickly to formalize its exit "however painful that process may be."
"Any delay would unnecessarily prolong uncertainty," they said in a joint statement.
The EU already is grappling with a refugee crisis and persistent economic woes. A Brexit forces it to reconcile losing its second-largest economy and a military powerhouse.
"Remain" campaigners had argued a Brexit would be disastrous for the British and even global economy — but the result showed voters were unswayed.
Instead, the “Leave” side — which railed against European regulations and increased migration in a heated campaign battle — was celebrating their triumph.
"We have our country back," tweeted U.K. Independence Party leader Nigel Farage, a key figure in the "Leave" campaign.
He later told reporters the referendum was "a victory for ordinary people, against the big banks, big business and big politics."
Britons who'd voted to remain were stunned by the result and nervous about what comes next.
"I'm really disappointed," said Charlotte English, 40. "I didn't want us to go out on a kind of anti-immigration, negative agenda."
The stay-at-home mom told NBC News that she used to live in France and now wonders what will happen with regards to visa-free travel in the EU.
"There's a lot of uncertainty. I think that's what I'm most stressed about," she explained.
That uncertainty hit markets particularly hard amid, given that the U.K. is the world’s fifth-largest economy.
Some analysts have warned Britain's exit could trigger a domino effect, prompting other EU members to mull their own departures from the bloc. Members of the far-right in other countries quickly cheered the result and called for referendums of their own.
Scotland's First Minister Nicola Sturgeon said her government would start drawing up legislation for a potential referendum on independence, saying she wouldn't let her country be removed from the EU "against our will."
Scots voted by 62 percent to 38 percent to stay in the EU, according to Friday's results, in contrast to the overall U.K.-wide result of 52 percent to 48 percent in favor of leaving.
A Brexit will undoubtedly shift the balance of power in Europe. France organized an emergency cabinet meeting and the EU assembly set an emergency session for next week amid the developments.
EU President Donald Tusk acknowledged he was "fully aware of how serious, or even dramatic" a political moment the bloc was facing but said it was "not a moment for hysterical reactions."
He stressed the need to "keep our unity as 27" nations — a number reflecting Britain's departure from the EU from the formerly 28-country bloc.
"What doesn't kill you makes you stronger," Tusk said in a statement.
Beyond the European implications, a Brexit also puts Britain’s so-called "special relationship" with the U.S. in an uncomfortable position. President Barack Obama had urged British voters to remain in the EU — the U.K. is America’s strongest military ally and the U.S. has a vested interest in its overall role in Europe.
He downplayed any fears of a potential rift on Friday, saying in a statement that "the special relationship between the United States and the United Kingdom is enduring."
"The people of the United Kingdom have spoken, and we respect their decision," Obama added.
Donald Trump, meanwhile, praised the results of the referendum while on a visit to Scotland.
"I think that it's a great thing," he told reporters. "They took back their country."
While the outcome of the referendum is clear, what comes next is anything but. Questions remain over how the exit will play out and what the U.K.'s new relationship with will Europe look like. Trade deals with the EU members must now be renegotiated. Will the scores of Europeans working freely in Britain — and vice versa — be forced to get work permits, or return home?
Nadine Michel, a 33-year-old German national living in London, wondered if she'd need a visa to stay in the country.
"Everyone kept texting me this morning saying 'What's gonna happen? Do we have to pick you up at the airport? Do you have to leave?" she told NBC News. "It's confusing and a bit terrifying, because basically we don't know what's gonna happen."
Amid the sweeping uncertainty former London mayor and leading "Leave" campaigner Boris Johnson told a press conference that Britain will not turn its back on Europe but can now "find our voice in the world."
"A voice that is commensurate with the fifth-biggest economy on earth: Powerful, liberal, humane and an extraordinary force for good," he said.
As Britons digested the news, the mood among pro-"Leave" supporters in London was electric.
"It's great, it's fantastic," 24-year-old electrician Michael Timon told NBC News. "We can finally start being Britain again. Start saving some money."
But mainland Europe — where many nations had pleaded with Britain to remain — was reeling.
Germany's Foreign Minister Frank-Walter Steinmeier calling the news "truly sobering."
"It looks like a sad day," he said in a statement.
French President Francois Hollande described the vote as a "tough test for Europe," while his Prime Minister Manuel Valls called it "an explosive shock."
"At stake is the break up pure and simple of the union," Valls said in a statement. "Now is the time to invent another Europe."
The divorce will take a minimum of two years to play out. In the meantime, the future of Europe remains uncertain.