BRUSSELS — In a bittersweet landmark, European Union leaders on Sunday approved an agreement on Britain's departure next year — the first time a member country will have left the 28-nation bloc.

It took leaders a matter of minutes at a summit in Brussels to endorse a withdrawal agreement that settles Britain's divorce bill, protects the rights of U.K. and EU citizens hit by Brexit and keeps the Irish border open. They also rubber-stamped a 26-page document laying out their aims for future relations after Britain leaves in March.

Barely half an hour after leaders sat down, European President Donald Tusk tweeted: "EU27 has endorsed the Withdrawal Agreement and Political Declaration on the future EU-UK relations."

British Prime Minister Theresa May, waiting in the wings as the other leaders met, joined them once they had given the deal the seal of approval to discuss the next steps on the road to Brexit.

May has hailed the deal as the start of a new chapter for Britain, but European Commission President Jean-Claude Juncker said the U.K.'s departure was a tragedy.

"It's a sad day," Juncker said as he arrived.

He told reporters that deal was "the best possible," but the summit "is neither a time of jubilation nor of celebration. It's a sad moment, and it's a tragedy."

The agreement paves the way for Britain's smooth departure from the bloc from the E.U. side, though a bumpy ride still awaits in the U.K.

In a formal statement endorsing the deal, the leaders called on E.U. institutions "to take the necessary steps to ensure that the agreement can enter into force on 30 March 2019, so as to provide for an orderly withdrawal."

The U.K. is due to leave the E.U. at midnight Brussels time on March 29.

E.U. chief negotiator Michel Barnier said now that the first phase was done, Britain and the E.U. needed to work for "an ambitious and unprecedented partnership."

"Now is the time for everybody to take their responsibility — everybody," he said.

Dutch Prime Minister Mark Rutte said the deal — the product of a year and a half of often grueling negotiations between Britain and the E.U. — was regrettable, but acceptable.

"I believe that nobody is winning. We are all losing because of the U.K. leaving," Rutte said. "But given that context, this is a balanced outcome with no political winners."

The last big obstacle to a deal was overcome on Saturday, when Spain lifted its objections over the disputed British territory of Gibraltar.

The deal must still be ratified by the European Parliament, something parliament President Antonio Tajani said was likely in January.

More dauntingly for May, it also needs approval from Britain's Parliament.

May is under intense pressure from pro-Brexit and pro-E.U. British lawmakers, with large numbers on both sides of the debate opposing the divorce deal and threatening to vote it down when it comes to the House of Commons next month.

Brexiteers think it will leave the U.K. tied too closely to E.U. rules, while pro-Europeans say it will erect new barriers between Britain and the bloc — its neighbor and biggest trading partner.

May insists her deal delivers on the things that matter most to pro-Brexit voters — control of budgets, immigration policy and laws — while retaining close ties to the U.K.'s European neighbors.

She plans to spend the next couple of weeks selling it to politicians and the British public before Parliament's vote in December.

In a "letter to the nation" released Sunday, May said she would be "campaigning with my heart and soul to win that vote and to deliver this Brexit deal, for the good of our United Kingdom and all of our people."

"It will be a deal that is in our national interest - one that works for our whole country and all of our people, whether you voted 'Leave' or 'Remain,'" she said.

She said Britain's departure from the E.U. "must mark the point when we put aside the labels of 'Leave' and 'Remain' for good and we come together again as one people."

"To do that we need to get on with Brexit now by getting behind this deal."