Conservative Party won the most seats in the UK general election last week, but not an overall majority and have been in coalition talks.
Brown officially tendered his resignation to the Queen at Buckingham Palace, and recommended Cameron to succeed him.
Speaking alongside his wife Sarah outside No 10 Downing Street, he said the job had been “a privilege” and wished his successor well.
His decision comes as the Tories and Liberal Democrats were poised to agree a deal to form a government.It was not yet known by Tuesday night whether they had reached a formal agreement with the Lib Dems to form a coalition.
Brown said he had taken the decision to resign after concluding he would not be able to form a government after days of talks between the parties following Thursday’s inconclusive election result.
‘Privilege to serve’
In an emotional farewell speech outside No 10, Mr Brown said he had “loved the job” and it had been “a privilege to serve”.
“I loved the job for its potential to make this country I love fairer, more tolerant, more green, more democratic, more prosperous and more just – truly a greater Britain.
“In the face of many years, challenges up to and including the global financial meltdown, I have always tried to serve, to do my best in the interests of Britain, its values and its people.”
Anticipating that, Brown said: “I wish the next prime minister well as he makes the important choices for the future.”
His two young sons joined him and wife Sarah for his brief statement which ended with the words: “Thank you and goodbye.”
Brown also said he would stand down as Labour leader with immediate effect.
Brown succeeded Tony Blair as prime minister in June 2007 after spending ten years as chancellor of the exchequer.
His resignation follows Thursday’s general election in which no party won an overall majority but the Conservatives won the most seats and votes.
Both Labour and the Tories had since been trying to persuade the Lib Dems to join them in a coalition government to run the country.
Brown had previously said he would resign as Labour leader, but stay on as prime minister until September, if Labour could agree a deal with the Lib Dems.
But after this possibility ended, the BBC’s Political Editor Nick Robinson said Brown decided he could not form a government and should stand down.
Robinson said Brown had made his announcement before the Conservatives and Lib Dems had formally announced they would be combining to form a government.
Before making his announcement, Brown consulted with his wife Sarah and close colleagues including Lord Mandelson, Douglas Alexander, Ed Balls and Ed Miliband.
Brown also spoke to former prime minister Tony Blair by phone.
Labour’s ruling National Executive Committee has indicated it wants Brown’s successor as leader to be chosen as soon as possible, possibly by the end of July. BBC