The disputed British territory is a key obstacle on the eve of a European Union summit on Sunday.

BRUSSELS — The European Union moved closer to sealing an agreement on Brexit after Spain said it had reached a deal with Britain over Gibraltar, a key obstacle on the eve of a European Union summit on Sunday.

Spanish Prime Minister Pedro Sanchez announced Saturday that Madrid would support the Brexit divorce deal after the U.K. and the EU agreed to give Spain a say in the future of the disputed British territory of Gibraltar, which lies at the southern tip of the Mediterranean nation.

Sanchez said that the deal is "is going to allow us to have direct negotiations with the U.K. regarding Gibraltar."

Shortly before Sanchez spoke at the Moncloa presidential palace in Madrid, EU spokesman Preben Aamann tweeted that after a phone conversation between Sanchez and EU Council President Donald Tusk "we are closer" to a deal before the Brussels summit when EU leaders are supposed to sign off on the Brexit agreement between Britain and the EU.

The tiny territory of Gibraltar — ceded to Britain in 1713 but still claimed by Spain — was the only dispute left hanging before the summit and had turned into an obstinate stumbling block.

On Friday, Spain said it wouldn't back the Brexit deal unless it gets a cast-iron guarantee of its say over Gibraltar's future.

Sanchez said the agreement reached would give Spain "absolute guarantees to resolve the conflict that has lasted for more than 300 years before Spain and the U.K."

British Prime Minister Theresa May, on her way to Brussels, hopes to leave Brussels on Sunday with a firm agreement on the withdrawal terms for Britain's departure from the EU on March 29, as well as a comprehensive negotiating text on how future relations should look like once both sides agree on a trade agreement.

May was expected to meet with European Commission President Jean-Claude Juncker and Council President Donald Tusk on Saturday evening.

Winning warm greetings from her 27 fellow leaders on Sunday might be much easier for May these days than getting such treatment from her Conservative party colleagues once she returns.

With the 585-page withdrawal agreement dealt with among negotiators and a vague statement on future relations both ready to be rubber-stamped on Sunday, Spain belated demands on Gibraltar had been taking center stage.

Portugal's foreign minister said Saturday that he backed the Brexit deal, including Spain's request to have its say on Gibraltar's future.

Foreign Minister Augusto Santos Silva said the original Brexit guidelines laid out last year that included assurances to Spain that it could deal with London directly on the issue of Gibraltar were "wise."

France has equally referred to the strong wording in last year's guidelines as the basis for compromise.

At home in the U.K, May's plans for Brexit continued to run into trouble.

The deputy leader of the Democratic Unionist Party in Northern Ireland used a party conference speech to try to persuade her to change course Saturday

Nigel Dodds told the conference in Belfast her proposed Brexit agreement reached with the EU would leave the U.K. in a "pitiful and pathetic place."

The small DUP has an outsize role because its support has been crucial to May's shaky government, which doesn't enjoy a majority in Parliament.

The party is threatening to end its support over the Brexit plan favored by May. That would imperil May's already difficult challenge in winning parliamentary support for her proposal.