LONDON — Prime Minister Theresa May struggled Monday to keep her government from imploding after the resignations of Foreign Secretary Boris Johnson, a tousle-haired frontman for Britain’s campaign to leave the European Union, and David Davis, her once-loyal “Brexit minister” in charge of negotiating the country’s split from the bloc.

Ever since May bungled the 2017 election, losing a majority in Parliament, there has been speculation over how long she would hold the top job. That question has never been more urgent.

As May prepares to meet this week with President Trump in his first official visit to Britain, hard-line Brexiteers are openly debating a no-confidence vote that could sweep her from power.

Johnson, a flamboyant politician and former mayor of London, once said, “My chances of being PM are about as good as the chances of finding Elvis on Mars.” He is divisive, and his stock has fallen lately. But the Whitehall mandarins and British political class have long assumed he covets the keys to 10 Downing Street. His departure hints at a possible leadership challenge within May’s Conservative Party.

In his resignation letter, Johnson wrote that the Brexit dream “is dying, suffocated by needless self-doubt.” He said that Britain was “headed for the status of colony — and many will struggle to see the economic or political advantage of that particular arrangement.”

“I am sorry — and a little surprised,” May wrote in reply.

Johnson’s allies say he did the honorable thing by resigning. His critics see selfish maneuvering.

May replaced Johnson on Monday with Jeremy Hunt, formerly the health secretary, who successfully secured a big bump in spending for the underfunded National Health Service. Hunt campaigned to remain in the E.U. but later said he had changed his mind. May named as Davis’s successor 44-year-old Dominic Raab, a leading pro-Brexit campaigner who served as her housing minister.

But the bombshell resignations expose May to further confrontations with restive Conservative Party members outraged over what they see as the prime minister’s plan for a “soft Brexit” that keeps Britain tied to many E.U. rules and regulations after it leaves the bloc in March 2019.

Backers of a hard Brexit, who want a decisive break from Brussels, are now in revolt. They denounced May’s latest road map as a fudge, a timid capitulation, a “Brexit in name only” that ignores the 52 percent of voters who opted in June 2016 to leave the E.U.

Tim Bale, a political expert at Queen Mary University of London, said that although May is in a difficult spot, “I don’t think it’s necessarily fatal for her — at the moment anyways.”

He said the Conservative Party doesn’t really have the appetite for another general election — because of the ongoing Brexit negotiations and because Tories haven’t coalesced around a candidate to champion. 

Johnson has “still got a bit of a fan club, but I’m not sure he’s the pinup that he once was,” Bale said. While some see an English original, others see a clown.

May paid tribute to Davis and Johnson in Parliament on Monday, even though “we do not agree about the best way of delivering our shared commitment to honor the result of the referendum.” When she praised Johnson for his “passion,” jeering erupted in the chamber. When she said Brexit had generated “a spirited national debate,” there were guffaws. 

May said she had listened to every possible idea and concluded that hers was the right one to pursue. She urged Brussels to seek compromise. “If the E.U. continues on this course, there is a serious risk it could lead to no deal, and this would most likely be a disorderly no deal,” she said. “A responsible government must prepare for a range of potential outcomes.”

Dominic Raab has been appointed as the new Brexit Secretary after David Davis resigned July 8 over the government's current plan for leaving the European Union. (Reuters)

Where May’s Brexit plans go now is an open question. Business leaders in Britain who run companies that make airplanes and automobiles are clamoring for answers and warning that Brexit is drifting toward the rocks.

The pound sterling slid after the Johnson resignation, while the markets ticked up.

Across the English Channel, ­reaction was muted.

“Politicians come and go, but the problems they have created for their people remain,” European Council President Donald Tusk said Monday of Davis’s exit, just before being informed of Johnson’s resignation. He said the same sentiment extended to Johnson as well. 

Tusk added: “The mess caused by Brexit is the biggest problem in the history of E.U.-U.K. relations, and it is still far from being resolved.”

Trump is scheduled to arrive Thursday for a visit that will be closely watched for any comments on Brexit and U.S. relations with the E.U. On Monday, White House press secretary Sarah Huckabee Sanders said in a statement, “The president continues to look forward to his working visit with the Prime Minister on July 13, and further strengthening the U.S.-U.K. special relationship.”

Last month, Johnson told an audience at a private gala dinner that he thought Trump would do a much better job at negotiating ­Brexit than his prime minister.

“Imagine Trump doing Brexit,” Johnson told his audience of Tory activists. “He’d go in bloody hard. . . . There’d be all sorts of breakdowns, all sorts of chaos. Everyone would think he’d gone mad. But actually you might get somewhere. It’s a very, very good thought.”

One of the leading campaigners for leaving the E.U., the radio show personality and European parliamentarian Nigel Farage, said Sunday: “For Brexit to succeed we must get rid of this awful, duplicitous PM.”

If May refuses to toughen her Brexit plan, angry Tories could seek a no-confidence vote. At least 48 Conservative members of Parliament would need to write letters to trigger it. Then May would need to win over the majority of Conservative lawmakers to stay in power.

Many commentators think she has the numbers to win such a vote. If she failed, a leadership contest would ensue — and in might step Johnson, among others.

In his letter of resignation late Sunday, Davis suggested that May’s promise that Britain and its Parliament would “take back control” from Brussels was hollow. He warned May that her approach would lead to further demands from Brussels and give Europe control of large swaths of the British economy.

For two years, chief negotiator Davis had been the white-haired, ruddy-cheeked face of Brexit. But talks in Brussels were notoriously slow, because May’s government could not — and still cannot — agree on what kind of future relationship Britain wants with Europe on trade, immigration, law, tariffs and border checks and security.

Recently it was revealed that ­Davis had attended only four hours of talks in Brussels this year, going as long as three months without meeting the E.U.’s chief negotiator, ­Michel Barnier.

David Lammy, a prominent member of the opposition Labour Party, derided Davis as “a man who can’t take responsibility. For two years he’s been in charge of Brexit. No one in the world is as much to blame for this monumental mess as himself.”

The prime minister had appeared to win over her fractious cabinet at a retreat on Friday, and a lengthy white paper staking out Britain’s vision for future relations with Europe was due to be published as soon as this week.

While May’s plan for exiting the E.U. has not been fully revealed to all members of her party — let alone to Parliament, the business community or the public — a brief outline shows that she supports a middle way of compromise with Brussels, keeping Britain closely aligned with Europe on standards, “a common rule book for industrial goods and agricultural products.” 

That, her critics say, would shackle Britain and make it “a rule taker versus a rulemaker.”

In Parliament, hard-line Brexit supporters are the most vocal but are not the majority. A compromise exit is supported by moderates across Parliament, including those in the Conservative and Labour parties, among others.

Jeremy Corbyn, the Labour Party leader, mocked May on Monday, saying it had taken her two long years to come up with a Brexit plan and only two days for that plan to unravel.

Michael Birnbaum in Brussels contributed to this report.