LONDON — Theresa May ended her failed three-year quest to lead Britain out of the European Union on Friday, announcing that she will step down as Conservative Party leader June 7 and triggering a contest to choose a new prime minister who will try to complete Brexit.

“I have done my best,” May said in a speech outside 10 Downing St., as close aides and her husband Philip looked on, before acknowledging that it was not good enough.

Concluding her remarks, she struggled to contain her emotions and her voice broke as she expressed “enduring gratitude to have had the opportunity to serve the country I love.”

Then she turned and strode through the famous black door of No. 10.

May will stay on as a caretaker prime minister until the new leader is chosen, a process the Conservatives aim to complete by late July. The new party leader will become prime minister without the need for a general election.

She became prime minister the month after the U.K. voted in June 2016 to leave the European Union, and her premiership has been consumed by the attempt to deliver on that verdict.

May was brought down by Brexit, but her nemesis wasn’t the EU, with which she successfully struck a divorce deal.

She was felled by her own Conservative Party, which refused to accept it. The plan was defeated three times in Parliament, rejected both by pro-EU opposition lawmakers and by Brexit-supporting Conservatives who thought it kept Britain too closely bound to the bloc.

Many Conservative lawmakers came to see May as an obstacle and blamed her for the U.K.’s failure to leave the EU on the scheduled date of March 29. The bloc has extended that deadline until Oct. 31 in hope Britain’s politicians can break their political deadlock.

The pressure on May reached breaking point this week as House of Commons Leader Andrea Leadsom quit and several Cabinet colleagues rejected the bill she planned to put before Parliament in a fourth attempt to secure lawmakers’ backing for her Brexit blueprint.

In her farewell speech, May defended her record, saying she had “negotiated the terms of our exit and a new relationship with our closest neighbors that protects jobs, our security and our Union.”

“I have done everything I can to convince MPs to back that deal,” she said. “Sadly, I have not been able to do so.”

“It is now clear to me that it is in the best interests of the country for a new prime minister to lead that effort,” she added.

Multiple contenders are already jockeying to replace her in a contest that will see a new leader chosen by Conservative lawmakers and party members. The early front-runner is Boris Johnson, a former foreign secretary and strong champion of Brexit. Other contenders are likely to include Leadsom, Foreign Secretary Jeremy Hunt and former Brexit Secretary Dominic Raab.

Johnson, whose relentless criticism helped push May out of the door, tweeted: “Thank you for your stoical service to our country and the Conservative Party. It is now time to follow her urgings: to come together and deliver Brexit.”

Whether it is Johnson or another contender, the next prime minister is likely to be a staunch Brexiteer, who will try to renegotiate the divorce deal, and if that fails, to leave the bloc without an agreement on the terms of the departure.

“The person who will replace her will embrace the possibility of a no deal with alacrity rather than fear,” said Steven Fielding, professor of political history at the University of Nottingham. “They will have to embrace it if they want to be elected by the Tory party membership.”

Most businesses and economists think that would cause economic turmoil and plunge Britain into recession. Parliament has voted to rule out a no-deal Brexit, though it remains the legal default option.

But many Conservatives think embracing a no-deal Brexit may be the only way to keep the support of voters who opted in 2016 to leave the EU.

The Conservatives expect to take a bruising when results come in late Sunday from this week’s European Parliament election, which many British voters are expected to use to express displeasure over the political gridlock. Opinion polls suggest Conservative voters deserting in droves to the single-issue Brexit Party led by Nigel Farage.

Any attempt to take Britain out of the EU without a deal will be fiercely resisted by Parliament, and could see pro-Europeans leave the Conservative Party.

Scottish First Minister Nicola Sturgeon, an opponent of Brexit, tweeted that May’s exit “will not solve the Brexit mess that the Tories have created. … The prospect of an even more hard-line Brexiteer now becoming PM and threatening a no deal exit is deeply concerning.”

EU leaders expressed respect for May, and stressed they would not renegotiate the Brexit deal.

“We have set out our position on the withdrawal agreement and on the political declaration,” said EU spokeswoman Mina Andreeva.

She said European Commission President Jean-Claude Juncker had great respect for May and would “equally respect and establish working relations” with any new British leader.

German Chancellor Angela Merkel said Germany would continue to “do everything it can to ensure there is a good partnership with Britain, an orderly exit, and then continuing good cooperation.”

U.S. President Donald Trump, who has sometimes differed publicly with May, said he was “feeling badly” for her.

“I like her very much,” said Trump who is due to meet May on a state visit to Britain June 3-5.

And May departed with a warning to her successor.

“To succeed, he or she will have to find consensus in Parliament where I have not,” she said. “Such a consensus can only be reached if those on all sides of the debate are willing to compromise.”

She said it had been “the honor of my life” to serve as Britain’s leader, the second woman to hold the job, after Margaret Thatcher.

“The second female prime minister — but certainly not the last,” May said.

• Associated Press writers Gregory Katz in London, Raf Casert in Brussels and David Rising in Berlin contributed.