The FTSE 100 and the pound plunged after the public backed Brexit by a narrow majority of 52 to 48 per cent.
His voice cracking with emotion, Mr Cameron said he would stay in office for three months to “steady the ship” then hand over to a new Prime Minister.
Boris Johnson was seen as a likely front-runner in a summer-long Tory leadership contest.
With wife Samantha standing behind him, Mr Cameron said the vote to leave was “an instruction that must be delivered”.
His decision came following a night of shock and turmoil after the first results at 1am from northern cities showed a surge for the Brexit door.
London and Scotland voted to stay but the final count showed 17,410,742 Britons elected to Leave, while 16,141,241 wanted to Remain. The turnout was 71.8 per cent. In other developments:
The FTSE 100 plunged seven per cent on opening at 8am before recovering some of the losses. At one stage it was down 460 points, equivalent to £115 billion off share values, with bank shares plummeting worst of all.
The Bank of England’s Governor Mark Carney came out to try to calm investors, saying: “We are well prepared for this.”
Ukip leader Nigel Farage hailed the UK’s “Independence Day”but Energy Secretary Amber Rudd said the so-called Project Fear warnings were already coming true. “We have made a very, very bad mistake,” she said.
The United Kingdom came under strain as nationalists in Scotland called for referendums to break away from England, while Sinn Fein’s Martin McGuinness demanded a referendum on a “united Ireland”.
European markets crashed even harder than the FTSE, with the French CAC 40 down eight per cent and Germany’s Dax fell by seven points.
Mayor of London Sadiq Khan called the result “a truly seismic event” but writing in today’s Standard he urged: “There is no need to panic. London will continue to be the successful city it is today.”
Labour was shocked as its traditional heartlands in the North of England and Wales led the Brexit surge. Leader Jeremy Corbyn faces plots to oust him, while one frontbencher threatened to “punch” former leader Ed Miliband.
Spain demanded a joint governorship over Gibraltar.
Ratings agency Standard & Poor’s warned that Britain was likely to be stripped of its coveted triple-A credit rating.
Sterling briefly touched a 30-year low of $1.30 before recovering partly, adding hundreds of pounds to many people’s summer holiday costs.
US presidential hopeful Donald Trump said it was a “great thing” that the people of the UK had “taken back their country” in voting to leave the EU as he touched down at his Trump Turnberry golf resort in Scotland.
Mr Cameron came out to the front of No 10 at 8.15am, dressed in a dark suit and blue tie, after informing the Queen of his decision to resign.
It became clear he was making a resignation statement when he began to list his achievements in office, including gay marriage.
He said of resigning: “This is not a decision I’ve taken lightly but I do believe it’s in the national interest to have a period of stability and then the new leadership required.”
Mr Cameron said he stood by his assertion that the UK could “find a way” to survive outside the EU. “Now the decision has been made to leave we need to find the best way and I will do everything I can to help,” he added.
Minutes after he spoke Mr Carney announced he was making £250 billion available to support markets and pledged that the Bank “will not hesitate to take additional measures as required as markets adjust and the UK economy moves forward”.
Foreign Secretary Philip Hammond admitted that Britain will have a weaker voice in European capitals, saying: “No one can possibly imagine our voice will carry weight in the EU from today.”
Mr Hammond also hinted at the spending cuts and tax rises threatened by Chancellor George Osborne during the campaign, saying the Government’s fiscal consolidation programme would now become “more difficult”.
Mr Cameron’s resignation threw a spotlight on to Mr Johnson. In an extraordinary scene, the ex-Mayor of London was greeted with jeers and boos from a huge crowd waiting outside his London home as he emerged and climbed into a car without making a statement at 9.30am.
There was a silence from Mr Osborne, but sources close to him said he was not going to resign. He had let it be known he warned against holding the referendum.
Labour grandee Lord Mandelson said he would “not be at all surprised” if there is an autumn general election.
Mr Farage milked the moment and is expected to launch a new Ukip strategy targeting Labour’s old heartlands for the next election. In a speech in front of jubilant supporters, he declared June 23 “our Independence Day”.
In France the National Front called for “Frexit” after the shock result.
Political leaders and officials in Brussels and other capitals went into emergency meetings to plan a response to the UK’s seismic decision.
European Council president Donald Tusk said there was “no way to predict all the political consequences of this event, especially for the UK” and appealed for calm.