LONDON (AP) — Theresa May entered No. 10 Downing St., on Wednesday as Britain’s new prime minister, following a bittersweet exit by David Cameron that was tinged with humor and regret.

“I was the future once,” Cameron quipped as he left office. But that future now belongs to May, and it involves instability, uncertainty and tough wrangling over Britain’s departure from the European Union.

Britain’s transition of power unfolded with startling speed since the June 23 referendum on EU membership. Cameron announced his resignation after voters rejected his appeal to stay in the 28-nation bloc, and May, the former home secretary, became Conservative Party leader Monday after an abbreviated contest in which her only remaining rival dropped out.

Then came Wednesday’s ceremonial choreography: Two trips to Buckingham Palace and two audiences with Queen Elizabeth II that ended with one prime minister out of a job and a new one curtseying to the monarch to begin her term.

May stood in front of the iconic door of No. 10 with her husband, Philip, as the 13th prime minister of the queen’s reign and the first woman to hold the job since fellow Conservative Margaret Thatcher served from 1979 to 1990.

She acknowledged that Britain faces a rocky road ahead as it undoes 43 years of EU ties and forges a new relationship with its neighbors.

“Following the referendum, we face a time of great national change,” May said. “And I know because we’re Great Britain we will rise to the challenge.

“As we leave the European Union we will forge a bold new positive role for ourselves in the world and we will make Britain a country that works not for a privileged few, but for every one of us,” she said.

May promised to fight for social justice in a speech that addressed “hard-working families” who have struggled during the years of instability since the 2008 financial crisis. Many of those people, fed up with remote politicians and bureaucrats, voted to leave the EU.

“When it comes to opportunity we won’t entrench the advantages of the fortunate few. We will do everything we can to help anybody, whatever your background, to go as far as your talents will take you,” May said, in language more often used by left-of-center politicians, rather than by members of the center-right Conservative Party.

May began appointing her new Cabinet within an hour of taking office, and several posts went to “leave” supporters.

The most notable was former London Mayor Boris Johnson, who was given the meaty job of foreign secretary, Britain’s top diplomatic post. The blond, Latin-speaking Johnson — a leader of the campaign for a British exit, or Brexit — had aspired to be prime minister himself before his bid failed because of party infighting.

Former Foreign Secretary Philip Hammond was named Treasury chief, ousting George Osborne, a strong “remain” voice in the referendum. May’s former job of home secretary went to Amber Rudd.

May has said she will create a new post of “Brexit” minister to oversee talks on a British EU exit from the 28-nation EU. That key job went to veteran Conservative lawmaker David Davis — a longstanding advocate of leaving the EU — and he will lead at least two years of negotiations with the bloc.

Wednesday’s carefully orchestrated political changeover began with Cameron making a final appearance in Parliament, turning the usually raucous prime minister’s question time into a session filled with praise, thanks, gentle ribbing, cheers — and a sprinkle of criticism.

Later, in a brief speech on Downing Street, the 49-year-old Cameron defended his government’s legacy.

“It has been the greatest honor of my life to serve our country as prime minister over these last six years, and to serve as leader of my party for almost 11 years,” he said. “It’s not been an easy journey, and of course we have not got every decision right, but I do believe that today our country is much stronger.”

Then, he and his wife, Samantha, and his children — 12-year-old Nancy, 10-year-old Elwen and 5-year-old Florence — left their home of six years and made the short drive to Buckingham Palace.

The palace soon confirmed that Cameron had “tendered his resignation as prime minister and First Lord of the Treasury, which her majesty was graciously pleased to accept.”

Minutes later, the palace released a photo of May curtseying to the monarch and confirmed that the queen had “requested her to form a new administration.”

As home secretary, the 59-year-old May has been in charge of immigration and law and order for the past six years. She has the tough task of calming the country and global financial markets after the upheaval that followed the referendum.

Although May had backed remaining in the EU, she has reassured “leave” supporters that “Brexit means Brexit, and we will make a success of it.”

Not all believe her. As May spoke in front of her new residence, a small band of pro-Brexit demonstrators down the street chanted “Theresa May, don’t delay!”

She is under pressure from pro-Brexit Conservatives and other EU leaders to start formal exit talks with the bloc. But Tony Travers of the London School of Economics said May probably would not rush to trigger Article 50 of the EU constitution, which starts a two-year countdown to a departure from Europe.

“I don’t detect Theresa May being an impulsive person,” Travers said. “I think she’s a cautious person, and the British political establishment needs to come to terms with this massive decision.”

Cameron used his final day in office to try to stake a claim on a legacy beyond his status as the prime minister who — by gambling on a referendum — took Britain out of the EU.

He said his government had cut the deficit, overseen economic growth and legalized same-sex marriage. And he offered the closest thing he has ever given to a mission statement: “I believe that politics is about public service in the national interest.”

“I will miss the roar of the crowd, Cameron told Parliament. “I will miss the barbs from the opposition.”

He ended by referring to a jibe he directed at then-Prime Minister Tony Blair more than a decade ago: “He was the future once.”

“Nothing is really impossible if you put your mind to it,” Cameron said. “After all, as I once said, I was the future once.”

He left the chamber to applause from all sides of the House and a standing ovation from his Conservative colleagues.