“The will of the British people is an instruction that must be delivered,” he said.
Using the past tense, he added: “I am very proud and honoured to have been prime minister of this country for six years.”
He said he had already spoken to the Queen to make his plans clear.
Cameron said he wants a new prime minister in place by the time of the Conservative party conference in October.
“The British people have made a very clear decision to take a different path. I think country requires fresh leadership,” he said.
The new prime minister will be in charge of triggering article 50 of the Lisbon treaty, the clause that kicks off the two-year process of withdrawal from the EU.
He also reassured European citizens in the UK that “there will be no initial change in your circumstances.”
“We must prepare for a renegotiation with the the EU,” he said.
The PM had urged the country to vote Remain in the EU but was defeated by 52% to 48% despite London, Scotland and Northern Ireland backing staying in.
UKIP leader Nigel Farage hailed it as the UK’s “independence day”.
The pound fell to its lowest level against the dollar since 1985 as the markets reacted to the results.
Britain is set to be the first country to leave the EU since its formation – but the Leave vote does not immediately mean Britain ceases to be a member of the 28-nation bloc.
That process could take a minimum of two years, with Leave campaigners suggesting during the referendum campaign that it should not be completed until 2020 – the date of the next scheduled general election.