Britain agreed Friday to concessions to the European Union in negotiating its split from the bloc, leaders said, as Prime Minister Theresa May overcame bitter divisions at home to advance to a crucial new phase of talks.

The bargain amounted to a capitulation by May on issues dear to the European Union: preserving peace and open borders in Northern Ireland, guaranteeing rights for the 3 million E.U. citizens living in Britain, and living up to British funding commitments in Europe for years to come.

On those issues and a host of others, Britain has been forced to fold to the European Union after saying earlier this year that it held the upper hand in the negotiations. Instead, British negotiators have found a largely united bloc that sees little need to give in to London’s demands. Friday’s agreement appears likely to unlock the next phase of the Brexit negotiation, focused on trade between the European Union and an unfettered Britain after it exits in March 2019.

Both sides warned that the coming talks will be harder than the first round, which lasted eight contentious months.

"It hasn't been easy for either side," May said in an early-morning news conference in Brussels following all-night talks, after a disagreement over borders between Northern Ireland and Ireland nearly derailed the deal earlier this week. She called the deal "a hard-won agreement in all our interests."

European Commission President Jean-Claude Juncker said he planned to recommend that European leaders approve advancing the talks when they meet at a summit next week.  They are expected to follow his advice.

“Sufficient progress has now been made on the strict terms of the divorce,” Juncker said. “This was a difficult negotiation for the European Union as well as for the United Kingdom.”

Despite the appearance of good cheer on both sides, significant tensions appeared to remain embedded in the agreement over the divorce deal, which will not be finalized until the very end of the full Brexit negotiation. British factions have squabbled about how to preserve the 1998 Good Friday Agreement, which depends on a borderless passage between the Republic of Ireland and Northern Ireland, as Britain seeks new trade independence that would typically require a border.

Friday’s deal appears to kick the can down the road on the topic, with Britain agreeing to maintain “full alignment” with E.U. customs and trade regulations in the absence of other solutions to preserve a borderless island of Ireland. May has had to thread a needle between the tiny Northern Ireland Democratic Unionist Party, which supports her weak government in Parliament and wants to ensure a seamless relationship with the rest of the United Kingdom, and hard-line Brexit advocates who want maximum independence from the European Union.

Irish Prime Minister Leo Varadkar said the promises by the European Union and Britain to preserve today's open border are “politically bulletproof” and “rock solid.”

“We have protected what we sought to protect, and we achieved what we sought to achieve,” the Irish leader said.

The two sides also compromised on how the rights of European citizens will be guaranteed in post-Brexit Britain. The European Union has pushed for an oversight role for the European Court of Justice, a judicial body in Luxembourg that anti-E.U. advocates in Britain have long loathed as a symbol of lost sovereignty. The agreement said the court would keep watch over citizens’ rights for eight years.

And Britain would agree to keep paying its budget commitments to the European Union for years to come, a proposal that avoids paying a single lump sum that could be politically unpopular, but would saddle London with E.U. budget obligations for decades. Estimates of the total bill range from $53 billion to $65 billion, more than double what May originally offered after triggering departure talks in March.

At every step of the negotiation, May has had to contend with roiling domestic politics that have pulled the British leader in conflicting directions. Her position was further weakened after she lost her parliamentary majority in June, making her more vulnerable both to Brexit hard-liners who want as final a rupture as possible and to doves advocating a more robust relationship with Europe.

The result has been to make it even harder to present a strong hand to the testy Europeans sitting across the table.

That means that some Brexit advocates endorsed Friday’s deal, even as others spitballed it.

“She’s gotten a deal in the interests of the whole U.K.,” said Michael Gove in a BBC interview, giving his sign-off as a leading Brexit hard-line campaigner.

Nigel Farage, the former leader of U.K. Independence Party and a staunch advocate of separation, said May was now able to “move on to the next stage of humiliation.” He called the deal “pathetic.”

May’s challenges were on sharp display on Friday, as the first minister of Scotland, Nicola Sturgeon, said she would fight to make sure any special concessions offered to Northern Ireland would also be available to the other nations within Britain. The pro-E.U. Sturgeon favors independence for Scotland.

The “devil is in the detail and things now get really tough,” Sturgeon wrote on Twitter. “Any special arrangements for [Northern Ireland] must be available to other UK nations.”

When E.U. leaders decide next week whether to unlock the next phase of the talks, they will probably also set out their demands for the transition period that Britain is seeking as it eases out of the bloc. They have indicated that they see little need to make concessions.

“Not everyone has understood that there are points that are nonnegotiable for the E.U.,” warned the chief E.U. negotiator, Michel Barnier.

European Council President Donald Tusk offered firm terms for the transition, saying that he believed E.U. leaders should demand that Britain face most of the requirements of E.U. membership even though it would no longer have any of the decision-making powers over the course of the roughly two-year transition period.

That “seems to be the only reasonable solution, and it is in the interest of all of our citizens that it be agreed as soon as possible,” Tusk said.

He warned that Britain had consumed much of its negotiating time on issues he said were easier than the thorny subjects to come. Large-scale free-trade agreements typically take years to hammer out. But if a deal is to be in place and approved before the March 2019 Brexit deadline, negotiators probably have less than a year, Tusk said.

The 27 remaining E.U. nations are also less likely to be united on trade the way they have been on the terms of the divorce, adding to the challenge of reaching a speedy deal.

“The most difficult challenge is still ahead. We all know that breaking up is hard. But breaking up and building a new relationship is much harder,” he said.

William Booth in London contributed to this report.

Read more