LONDON — After a five-hour meeting with her cabinet, and months of struggle and delay, Prime Minister Theresa May emerged from 10 Downing Street on Wednesday and announced that her ministers had approved her Brexit plan.

The draft agreement, negotiated by British and European Union officials, is a decisive step toward finalizing Britain’s departure from the European Union in March.

The agreement, which has been compared to the world’s most complex divorce settlement, lays out the billions of euros that Britain will pay to leave, what rights Europeans living in Britain will have after Brexit, and how a 21-month transition period will work. The agreement also promises a solution to the knotty challenge of avoiding a hard border between Northern Ireland, which is part of the United Kingdom, and the Irish Republic, which will remain in the E.U.

The plan still requires endorsement by European leaders this month, which should be relatively easy, to be followed by a far more difficult vote in December in the British Parliament, where many members decry the draft deal as a weak capitulation that satisfies no one.

The cabinet approval of May’s package marked the end of a remarkable 24 hours in British politics — a true cliffhanger, with social media and the airwaves filled with speculation about whether the deal, and May herself, would survive.

Even as May prepared to speak, British political reporters were tweeting that a challenge to her leadership might be underway.

The prime minister looked exhausted as she faced the cameras Wednesday evening outside her official residence. Rather than celebrate a hard-won round in her fight for a workable Brexit deal, she sounded somber.

“This is a decision that will come under intense scrutiny, but the decision was to build a future for our country or to go back to square one and fail on the promise of the referendum,” May said, without elaborating on the details of the deal.

She described a “long, detailed and impassioned debate” within her cabinet, whose ranks are balanced between those who, like May, voted against Brexit two years ago, and those who campaigned hard for it — ministers such as Michael Gove and Liam Fox, who are committed Brexiteers.

May said the Brexit withdrawal agreement will protect jobs and preserve the United Kingdom. She did not say that it would make Britain great again.

“I firmly believe with my head and my heart that this is a decision that is in the best interests of the entire United Kingdom,” May said.

The withdrawal agreement was published shortly after she spoke — 585 pages of E.U. legalese. May will discuss it in Parliament on Thursday.

For the past two years, the greatest debate over Brexit has not been waged between Brussels and London, but within May’s fractious Conservative Party.

Hard-line Brexiteers have pushed for a decisive split from European bureaucrats and courts, from E.U. rules and regulations, while others, led by May, have sought a softer Brexit, a compromise package that keeps Britain more closely aligned with Europe to better protect the British economy.

May got a taste of the disgruntlement of her own backbench on Wednesday, as fellow Conservative Party members heaped derision on a deal that they had not yet seen — but that they feared gave too much away.

Conservative member of Parliament Peter Bone warned May that she was “not delivering the Brexit people voted for.” He said, “Today you will lose the support of many Conservative MPs and millions of voters across the country.”

Arch-Brexiteer Boris Johnson, who quit his job as foreign secretary over May’s proposals in July, had urged cabinet members to reject the agreement. “It’s vassal-state stuff,” Johnson said. “For the first time in 1,000 years, this place, this Parliament, will not have a say over the laws that govern this country.”

A Conservative member of Parliament who opposes Brexit, Anna Soubry, said Wednesday that British voters should be offered another chance to cast a ballot on whether to support May’s deal or remain in the European Union.

The best deal, Soubry told the BBC, “is the deal that we currently have with the European Union.”

Sammy Wilson, a member of Parliament for Northern Ireland’s Democratic Unionist Party (DUP), which May needs to prop up her minority government, told TalkRadio that May’s plan “is not so much a deal as a double-cross.” 

The DUP’s chief whip at Westminster, Jeffrey Donaldson, said May’s half-in, half-out plan “doesn’t give the United Kingdom as a whole the opportunity to do free-trade deals and to take control of its own future.”

Most lawmakers in the opposition Labour Party are expected to vote against the plan if and when it reaches Parliament. Ahead of the release of the document Wednesday, Labour leader Jeremy Corbyn said: “From what we know of the shambolic handling of these negotiations, this is unlikely to be a good deal for the country.”

Outside Parliament, Nigel Farage, a top Brexit campaigner and a member of the European Parliament, called May’s withdrawal agreement “the worst deal in history.”

In Europe, there was relief that May had won approval from her divided cabinet.

“Green light!” Danish Prime Minister Lars Loekke Rasmussen tweeted. “Relieved that the UK government has now approved the deal reached by our negotiators.”

“This agreement is a crucial step in concluding these negotiations,” said the chief E.U. Brexit negotiator, Michel Barnier, in a late-night news conference in the E.U. capital of Brussels, where he triumphantly waved a copy of the agreement, which he said contained 185 articles, three protocols and a series of annexes. “We’re practically there.”

He said European leaders had been united after what he described as Britain’s “thunderclap” decision to leave the European Union and took pains not to inflame May’s sticky political situation in London.

But he confirmed that if negotiators fail to reach a second deal about Britain’s future relationship with the E.U. in the coming two years, a fail-safe, politically painful insurance policy would kick in to prevent a border from springing up between Ireland and Northern Ireland.

That insurance plan would keep Britain bound inside the E.U. customs zone, obeying E.U. customs rules and regulations but unable to shape them — the exact opposite of the stated goal of Brexit advocates. European officials say they, too, find the situation uncomfortable, since Britain would have tariff-free and quota-free access to the vast E.U. market without being subject to the same demands as other E.U. countries.

In London, May’s approach had few defenders. But among them was former Conservative Party leader William Hague, who asked his colleagues, “Did anybody really think you could leave the E.U. without a lot of compromises?”

Hague urged skeptics to consider the “big picture.” He told the BBC that the deal fulfills the mandate the British voters chose when they voted 52 percent to 48 percent in a June 2016 referendum to leave the European bloc.

“If what you want is to deliver on leaving the European Union, and have frictionless trade in goods at the border for the next few years until a future free-trade agreement comes into force, and have control of our own immigration policy, and keep the United Kingdom together, all at the same time — well, then, a deal is going to look pretty much like this one seems to look like. It isn’t going to be dramatically different from that,” Hague said.

Quentin Ariès and Michael Birnbaum in Brussels contributed to this report.