By Elizabeth Piper and Alastair Macdonald
BRUSSELS (Reuters) - British Prime Minister Theresa May will seal a Brexit package deal with European Union leaders in Brussels on Sunday after an agreement to reassure Madrid on a future say on Gibraltar lifted a threat of a Spanish veto.
The 27 EU national leaders will gather for an hour or so to formally endorse both a detailed treaty setting out the terms on which Britain will leave in an orderly manner on March 29 and a declaration outlining how Britain can keep close to its biggest market by following many EU rules after a 2-4-year transition.
They will then meet May briefly as she seeks momentum to get the package through the British parliament in the coming weeks in the teeth of fierce opposition from many of her own allies.
The Democratic Unionist Party, whose votes from Northern Ireland have helped May to govern since she lost her majority in a misjudged snap election last year, said it would try to block a Brexit deal it called "pitiful" - partly because it binds London to many EU rules it will no longer help set and partly as the DUP fears it could weaken the province's ties to Britain.
No one knows what will happen if parliament rejects May's plan, which she and EU leaders say is the best deal available.
Wrangling over how to keep open troubled Northern Ireland's land border with the EU without creating disruptive customs barriers with the Irish Republic dogged much of the 18 months of talks before accords were struck this month. Another relic of the imperial past, Britain's 300-year-old naval base on Spain's southern coast, threatened to derail plans at the last minute.
Spanish Prime Minister Pedro Sanchez threatened to boycott Sunday's meeting if he did not get amendments to the deal to ensure Madrid gets a say in Gibraltar's future ties with the EU.
After officials wrangled through the night, he announced on Saturday afternoon that he had such written pledges. Brussels officials said those essentially confirmed what most EU leaders had already understood - that Spain must have a binding say over how any future EU-UK trade pact might affect Gibraltar.
May will meet Sanchez for face-to-face talks during the summit, officials said.
(Additional reporting by Gabriela Baczynska and Jan Strupczewski in Brussels; writing by Alastair Macdonald; Editing by Marguerita Choy)