BRUSSELS — The European Union removed the last major obstacle to sealing an agreement on Brexit after Spain said it had reached a deal Saturday with Britain over Gibraltar on the eve of a summit where EU leaders will sign off on the divorce papers.

British Prime Minister Theresa May, who held preparatory talks with EU leaders Saturday evening, will then have the momentous task of selling the terms of the deal to a recalcitrant British Parliament and a nation still fundamentally split over whether the U.K. should leave the EU on March 29 and under what conditions.

May vowed to campaign "with my heart and soul" to win Parliament's backing for the deal."

Spanish Prime Minister Pedro Sanchez, who had threatened to oppose the deal, announced Saturday that Madrid would support the divorce agreement after the U.K. and the EU underscored Spain's say in the future of the disputed British territory of Gibraltar, which lies at the southern tip of the Mediterranean nation.

Spain wants the future of the tiny territory, which was ceded to Britain in 1713 but is still claimed by Spain, to be a bilateral issue between Madrid and London, not between Britain and the EU.

In a letter obtained by The Associated Press, European Commission President Jean-Claude Juncker and European Council President Donald Tusk assured Sanchez that Spain's "prior agreement" would be needed on matters concerning Gibraltar.

Spain claimed a major diplomatic victory.

"Europe and the United Kingdom have accepted the conditions imposed by Spain," Sanchez said. "Therefore, as a consequence of this, Spain will lift its veto and tomorrow will vote in favor of Brexit."

But Britain said the statement merely clarified the existing state of affairs. May said Britain had conceded nothing on the sovereignty of Gibraltar.

"I will always stand by Gibraltar," May said. "The U.K. position on the sovereignty of Gibraltar has not changed and will not change."

The move should allow EU leaders speedily to sign off on the Brexit agreement at a special summit Sunday morning.

May hopes to leave EU headquarters on Sunday with a legally binding agreement on the withdrawal terms for Britain's departure from the EU on March 29, as well as an ambitious but vague political declaration on future relations between the two sides.

Winning warm greetings from her 27 fellow leaders on Sunday will likely be easier for May than getting friendly treatment from her colleagues in government and Parliament once she returns. The British leader is under intense pressure from pro-Brexit and pro-EU 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 Parliament next month.

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

The leader of Northern Ireland's Democratic Unionist Party, on which May relies to get her government majority, on Saturday reinforced her party's rejection of the Brexit deal. The DUP opposes plans for keeping the border between Northern Ireland and EU member Ireland open after Brexit, saying it weakens the ties binding the U.K. by creating separate trade rules for Northern Ireland.

Arlene Foster said in Belfast that the agreement leaves Northern Ireland "open to the perils of increased divergence away from the rest of the United Kingdom."

The DUP has said it may drop its backing of the government because of the Brexit plan.

May insists her deal delivers the 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" before Sunday's summit, 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."

She said Britain's departure from the EU "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."