Gordon Brown tonight announced he was tendering his resignation as Prime Minister.
Mr Brown said he had notified the Queen's private secretary he was advising that she should appoint David Cameron as the new premier.
Mr Brown, his voice cracking with emotion, also said he was resigning immediately as Labour leader.
He said it had been "a privilege to serve" and wished his successor well.
Mr Brown then left Downing Street for Buckingham Palace holding hands with his wife Sarah and sons John and Fraser.
With his wife Sarah standing by his side on the steps of No 10, he said: "My constitutional duty is to ensure that a government can be formed after last week's general election.
"I have informed the Queen's private secretary that it is my intention to tender my resignation to the Queen.
"If the Queen accepts, I shall advise her to invite the Leader of the Opposition to seek to form a government."
Mr Brown said: "I wish the next prime minister well as he makes the important choices for the future.
"Only those who have held the office of prime minister can understand the full weight of its responsibilities and its great capacity for good.
"I have been privileged to learn much about the very best in human nature and a fair amount too about its frailties - including my own."
Mr Brown was taken directly to Buckingham Palace, where he was greeted and taken inside for his audience with the Queen.
Mr Brown said he had "loved the job, not for its prestige, its titles and its ceremony, which I do not love at all.
"No, I loved the job for its potential to make this country I love fairer, more tolerant, more green, more democratic, more prosperous, more just - truly a greater Britain."
He also paid tribute to the armed forces, saying: "Now that the political season is over, let me stress that having shaken their hands and looked into their eyes, our troops represent all that is best in our country and I will never forget all those who have died in honour and whose families today live in grief."
He paid tribute to colleagues and staff, who had been "friends as well as brilliant servants of the country".
Comments: Our rules
We want our comments to be a lively and valuable part of our community - a place where readers can debate and engage with the most important local issues. The ability to comment on our stories is a privilege, not a right, however, and that privilege may be withdrawn if it is abused or misused.
Please report any comments that break our rules.
Read the rules here