Global financial markets plunged as results from Thursday's referendum showed a near 52-48 percent split for leaving.
The pound fell more than 10 percent against the dollar to levels last seen in 1985, its biggest one-day fall in history, and European shares plummeted more than 8 percent, headed for their biggest ever one-day fall.
Billions of dollars were wiped off European banks' market value, with Britain's Royal Bank of Scotland, Barclays and Lloyds Banking Group the biggest fallers.
Cameron, who lost his gamble betting the nation's future on an outcome he predicted would be catastrophic, said he would resign as prime minister by October.
"I do not think it would be right for me to be the captain that steers our country to its next destination," he said in a televised address outside his Downing Street office.
Quitting the EU could cost Britain access to the EU's trade barrier-free single market and mean it must seek new trade accords with countries around the world. The United Kingdom itself could break apart, with leaders in Scotland -- where nearly two-thirds of voters wanted to stay in the EU -- calling for a new vote on independence.
The EU for its part will be economically and politically damaged, facing the departure not only of its most free-market proponent but also a member with a U.N. Security Council veto and powerful army. In one go, the bloc will lose around a sixth of its economic output. Populist leaders in France and the Netherlands demanded their own referendums to leave.
The vote will initiate at least two years of divorce proceedings with the EU, the first exit by any member state. Cameron said it would be up to his successor to formally start the exit process.
His Conservative Party rival Boris Johnson, the former London mayor who became the most recognisable face of the "leave" camp, is now widely tipped to seek his job.
European politicians reacted with shock. "Please tell me I'm still sleeping and this is all just a bad nightmare!" former Finnish Prime Minister Alexander Stubb tweeted.
French National Front leader Marine Le Pen declared "Victory for freedom!". Dutch far right leader Geert Wilders said: "We want be in charge of our own country, our own money, our own borders, and our own immigration policy."
Britain, which joined the then European Economic Community (EEC) in 1973, has always been an ambivalent member. A firm supporter of free trade, tearing down internal economic barriers and expanding the EU to take in ex-communist eastern states, it opted out of joining the euro single currency or the Schengen border-free zone.
Cameron's ruling Conservatives in particular have risked being torn apart by euroscepticism for generations.
World leaders including Obama, Chinese President Xi Jinping, German Chancellor Angela Merkel, NATO and Commonwealth governments had all urged a "Remain" vote, saying Britain would be stronger and more influential in the EU than outside.
The four-month campaign was among the divisive ever waged in Britain, with accusations of lying and scare-mongering on both sides and rows on immigration which critics said at times unleashed overt racism.
It also revealed deeper splits in British society, with the pro-Brexit side drawing support from millions of voters who felt left behind by globalisation and believed they saw no benefits from Britain's ethnic diversity and free-market economy.
A pro-EU member of parliament was stabbed and shot to death in the street a week ago by an attacker who later told a court his name was "Death to traitors, freedom for Britain". Older voters backed Brexit; the young mainly wanted to stay in.
But in the end, concerns over uncontrolled immigration, loss of sovereignty and remote rule from Brussels appear to have trumped almost unanimous warnings of the economic perils of going it alone.
[Reuters]