David Cameron insisted he was leaving Britain "stronger" as he said an emotional goodbye to Downing St flanked by his wife Samantha and their children.
In a parting speech before heading to Buckingham Palace to tender his resignation, the Prime Minister admitted he had not got everything right.
"It's not been easy going and of course we have not got every decision right. But I do believe that today our country is much stronger," he said.
Cameron thanked his family for keeping him "vaguely sane" during his six years in office, and described Samantha as the "love of my life".
Buckingham Palace officially announced just before 5.25pm (British time): "The Right Honourable David Cameron MP had an audience [with] the Queen this evening and tendered his resignation as Prime Minister and First Lord of the Treasury, which Her Majesty was graciously pleased to accept."
Five-year-old Florence Cameron appeared to wipe away tears as she watched her father make his valedictory comments. Long-standing aides to the PM were also visibly upset.
Mr Cameron said: "When I first stood here in Downing St on that evening in May 2010, I said we would confront our problems as a country and lead people through difficult decisions so that together we could reach better times.
"It's not been an easy journey and of course we have not got every decision right but I do believe today our country is much stronger.
"Above all it was about turning around the economy and, with the deficit cut by two thirds, 2.5 million more people in work, and one million more businesses, there can be no doubt that our economy is immeasurably stronger.
"Politicians like to talk about policies but at the end it is about people's lives. I think of the people doing jobs who were previously unemployed. I think of the businesses that were just ideas in someone's head and that today are making a go of it and providing people with livelihoods."
Paying tribute to his family, the outgoing PM said: "I want to thank my children � Nancy, Elwen and Florence, for whom Downing St has been a lovely home over this last six years. They sometimes kick the red boxes full of work. Florence � you once climbed into one before a foreign trip and said: 'Take me with you'.
"Well, no more boxes.
"And above all I want to thank Samantha, the love of my life. You have kept me vaguely sane and as well as being an amazing wife, mother and businesswoman, you've done something every week in that building behind me to celebrate the best of voluntary service in our country."
Setting out what he sees as his legacy, Mr Cameron said: "I think of the hard-working families paying lower taxes and getting higher wages because of the first national living wage.
"I think of the children who were languishing in the care system and who have now been adopted by loving families. I think of the parents now able to send their children to good and outstanding schools, including free schools that simply didn't exist before.
"I think of over 200,000 young people taking part in national citizens service, the first youth programme of its kind in the world, something again that wasn't there six years ago.
"I think of the couples who have been able to get married who were not allowed to in the past. And I think of the people in the other side of the world who would not have had clean drinking water, the chance to go to school or even be alive were it not for our decision to keep our aid promises to the poorest people and the poorest countries in our world."
Cameron lavished praise on May, who was confirmed as Tory leader this week and will now steer Britain towards its exit from the EU.
"I will advise Her Majesty to invite Theresa May to form a new administration. I am delighted that for the second time in British history, the new Prime Minister will be a woman and once again a Conservative.
"I believe Theresa will provide strong and stable leadership in fulfilling the Conservative manifesto on which we were elected and I wish her well in negotiating the best possible terms for Britain's exit from the European Union.'
Cameron also extended warm thanks to his team and No 10 and across Whitehall.
He said: "I want to thank everyone who has given so much to support me personally over these years.
"The incredible team in No.10, the civil servants, whose professionalism and impartiality is one of our country's greatest strengths.
"And my political advisers, some of whom have been with me since the day I stood for my party's leadership 11 years ago."
Cameron added: "The spirit of service is one of this country's most remarkable qualities.
"I have seen that service day in and day out in the incredible work of our armed forces, our intelligence agencies and our police. It is something I always knew. But as Prime Minister you see it so directly that it blows you away.
"And of course writing those heart-breaking letters to the families who have lost loved ones is a poignant reminder of the profound scale of what these men and women give for us in the defence of our freedoms and our way of life. We must never forget that.
"In a different way, I have seen that same spirit of service in the amazing contributions of countless volunteers in communities up and down our country who are making our society bigger and stronger.
"And I am proud that every day for the past two years I have used the office of Prime Minister in a non-political way to recognise and thank almost 600 of them as Points of Light whose service can be an inspiration to us all.
"For me politics has always been about public service in the national interest. It is simple to say but often hard to do."
In a wise-cracking and sometimes emotional swansong, the Prime Minister said he would miss "the roar of the crowd" as he was cheered to the rafters by Tory MPs.
Samantha Cameron and the children were in the public gallery as glowing tributes were paid to his "public service" and achievements in office.
Tory MPs gave him a rare standing ovation at the end of his performance, as did some Labour MPs -- but leader Jeremy Corbyn and most of his frontbench remained stubbornly in their seats.
Cameron has been jousting at the regular clashes since becoming Conservative leader in 2005, when he first lined up against Tony Blair.
As the session kicked off, Cameron as usual gave details of his engagements for the day, but joked: "Other than one meeting this afternoon with Her Majesty the Queen, the diary for the rest of my day is remarkably light."
Asking the first question, Ulster Unionist MP Danny Kinahan paid tribute to the outgoing PM and suggested he might want to look at the vacancies for presenter of the BBC's Top Gear, the England football team or US president.
Cameron thanked him for the "fascinating suggestions for future jobs" but added: "Most of which sound even harder than this one so I think I'll pass."
Labour MPs sat in silence as Corbyn, who is facing a major rebellion, rose to pay tribute to Cameron.
But Cameron could not resist responding with a jibe about Labour's failure to get a woman Prime Minister elected.
"When it comes to women prime ministers it's two nil � and not a pink bus in sight," he said.
The PM launched a series of parting shots at Corbyn, likening him to the knight from Monty Python's Holy Grail film who has limbs chopped off but dismisses the injuries as a "flesh wound".
Mr Cameron addressed a topic of much discussion this week � whether the 10 Downing St cat Larry would be moving with the Camerons.
He told MPs: "The rumour that somehow I don't love Larry, I do. I can't take Larry with me, he belongs to the house and the staff love him very much, as do I."
Corbyn used his last question to wish Cameron and his family well, as well as attempting to make a joke about the outgoing PM filling a new vacancy on Strictly Come Dancing.
He told Cameron: "Could I just put on record and wish him well as he leaves this office and also to wish his family well.
"It's the loved ones nearest to us and our families that actually make enormous sacrifices.
"I'd also like him to pass on to his mum my thanks on ties and suits and songs.
"There's a rumour going round that his departure has been carefully choreographed so he can slip seamlessly into the vacancy created this morning by Len Goodman's departure.
"Can he confirm if that is correct?"
Cameron said it was right to reflect on the burden carried by politicians' families, praising his "amazing wife Sam and my lovely children".
Cameron mocked the Labour party's chaos in response to Corbyn accusing him of failing to eradicate poverty.
The outgoing PM said: 'To be accused of slow-thin delivery by the Right Honourable gentleman, let's just take the last week - we've both been having these leadership elections.
''We got on with it, we've had resignation, nomination, competition and coronation; they haven't even decided what the rules are yet.
''If they ever got in to power it would take them about a year to work out who sits where.''