European leaders signed off Sunday on their split with Britain, approving a deal that would set the United Kingdom on a new road, independent from the European Union after more than four decades of membership in the political and economic powerhouse. 

The agreement — “historic,” according to German Chancellor Angela Merkel — will cut Britain out of the European Union, marking the first time a nation has ever sought to depart the bloc. But the deal must still weather Britain’s political storms ahead of the official March 29 exit date, with the key test next month when Britain’s Parliament puts it to a vote amid strong opposition.

No matter the uncertainty in Britain, Sunday’s meeting was a momentous occasion in the country’s 45-year-long membership in the European club and its tortuous two-year effort to depart it.

The agreement will almost certainly come with steep costs for both sides, leaving leaders in the extraordinary position of negotiating a split that they almost all believe will harm their citizens. Some E.U. leaders said they felt Sunday’s deal was a tragedy. The accord, approved unanimously Sunday by the remaining 27 E.U. leaders, would leave Britain in legal limbo — obligated to follow most E.U. rules but no longer a member — until the end of 2020, as leaders haggle over the relationship to come. The assent came after less than an hour of discussion.

“My feelings are very divided,” Merkel said after the meeting, a rare and unusual gathering of European leaders on a chilly Sunday morning in Brussels. “I feel very sad, but at the same time I feel a sense of relief.”

Asked if she shared the unhappiness, British Prime Minister Theresa May said, “No, but I recognize that others do.”

May said the British Parliament will now face “one of most significant votes Parliament has had in many years,” and she would campaign for it with all her heart.

“This is the deal on the table,” she said. “It is best possible deal. It is the only deal.”

Under the terms, Britain will face a $50 billion bill to pay its financial commitments on its way out the door. It will be tied to E.U. laws and regulations for years in some areas, and its ability to negotiate its own trade deals — a key demand of the Brexiteers who led a successful rebellion against the established order in 2016 — could be tightly limited. But it will no longer be obligated to allow E.U. citizens to live and work within its borders, and May has sought to promote that as a major victory, even as other leaders shake their heads about the situation.

“The cost we discussed in recent months is massive,” French President Emmanuel Macron said. “Those who said to the British they would save several dozens or hundreds of billions of pounds lied to them.”

British and E.U. negotiators will still have to work out the terms of their future relationship, and although a 36-page declaration that was also approved Sunday set out some of the ­guidelines, much remained un­resolved, including Britain’s freedom to control large parts of its own economy.

Arriving at this point in the divorce has been a struggle: 17 months of fraught negotiations, marked by nonstop bickering within May’s own leadership team, including a string of high-profile resignations from her cabinet

May’s headaches are far from over. Her limits as a vote-wrangler will be tested in her own Parliament, where pro-Brexit lawmakers have hammered the plan, saying it fails to break decisively enough from Brussels, and pro-E.U. forces have condemned it as a self-inflicted wound that hurts British voters.

According to the British news media, as many as 90 lawmakers of May’s own Conservative Party have said they plan to vote against it, alongside members of the opposition Labour Party.

The plan seeks to avoid a “hard” border between the Republic of Ireland, which is remaining in the European Union, and Northern Ireland, which will depart. It also seeks to prevent an internal split between Northern Ireland and the rest of the United Kingdom. To do so, the two sides agreed that if they fail to come up with a better plan before the end of Britain’s transition period, London will remain locked inside the European customs union, obligated to respect most E.U. regulations on goods that would pass between the two sides, including tariffs with the rest of the world.

In addition to the divorce deal, May and her European counterparts approved a political declaration on the future relationship between the two partners. Unlike the withdrawal agreement, which will be legally binding after it is approved by the British and European parliaments, the political document is loosely worded and aspirational, an outline for future talks that will probably take years to complete. It contains a list of hoped-for outcomes on trade, customs inspections, tariffs, fishery rights, aviation and the ability of citizens to visit and live in the other’s territory. 

Even the vague aspirations, however, are likely to disappoint British business interests. For example, while May has long sought to replicate the “frictionless” trade that exists today between members of the European Union, a post-Brexit Britain will face “separate markets and distinct legal orders,” according to the political declaration, while aligning with E.U. rules. And London’s financial center, one of the largest in the world, will see its access to Europe diminished when it surrenders its “passport” rights to move money.

Boris Johnson, the former British foreign secretary and lead campaigner for Brexit, said on Saturday that Britain was “on the verge of a historic blunder.” He said May’s withdrawal deal surrenders too much power to Brussels.

What will happen to the withdrawal agreement if it is voted down by the British Parliament is unclear. May could put it up for a vote again. She could face a leadership challenge or new elections. Britain could even rerun its separation referendum, although few analysts say this is realistic. Brexiteers want negotiators to return to Brussels to amend the deal, but European leaders have said there is nothing more to talk about. They advised British lawmakers to take what is on the table.

The disagreements have left the two sides staring into the abyss, as British opponents of the deal say they want to come up with something better. E.U. leaders say the alternative is a chaotic no-deal departure — a development that could ignite an economic crisis and could even lead to shortages of medicine in Britain.

Europe has largely held united through the negotiations, vowing that if Britain leaves the club, it must no longer enjoy the benefits. Leaders generally dislike the departure but want to pin down the deal to free them to focus on other, more pressing problems, such as populism, struggling economies and Russia.

Their main goal Sunday appeared to be to try to move on from the bitter breakup.

“Nobody is winning. We are all losing because of the U.K. leaving,” Dutch Prime Minister Mark Rutte said.

Quentin Ariès contributed to this report.