BRUSSELS/LONDON (Reuters) - Britain and the European Union have agreed a draft text setting out a close post-Brexit relationship, though wrangling with Spain over control of Gibraltar must still be settled before EU leaders meet on Sunday in order to rubber-stamp the pact.

Thursday’s news sent the pound nearly 1 percent higher on relief among investors that 18 months of tense and tortuous negotiation were bearing fruit, keeping Britain close to its biggest market and ensuring nothing much will change during a transition period due to last until at least the end of 2020.

“The British people want Brexit to be settled. They want a good deal that sets us on a course for a brighter future,” British Prime Minister Theresa May told parliament.

“The deal that will enable us to do this is now within our grasp. In these crucial 72 hours ahead, I will do everything possible to deliver it for the British people.”

Her spokesman said she believed she could win a critical vote in parliament on the deal, expected next month, but many of those she needs to persuade appeared unconvinced.

Some fellow Conservatives seeking a cleaner break from the EU accused her of “betraying Brexit” while opposition Labour leader Jeremy Corbyn called the outcome of the negotiations “the worst of all worlds” for keeping Britain linked to the vast EU market but without a say in its rules.

After a draft treaty last week set the terms for Britain’s departure in March, May had met EU chief executive Jean-Claude Juncker on Wednesday, hoping to finalize an ambitious declaration on future ties that could help her secure backing at home for the entire Brexit package.

But the deal faces a rocky ride once it reaches a deeply divided British parliament, with hardline eurosceptic and staunch pro-EU factions, and various shades of gray in-between.

EU officials said there was a solid consensus that remaining niggles should not hold up a final deal for Sunday, as the other 27 governments go through the new paperwork.

The main question mark is whether Spain, seeing Brexit as an opportunity to swing the EU’s weight behind its 300-year campaign to reclaim Gibraltar from Britain, can be persuaded to remain patient.

Spanish Prime Minister Pedro Sanchez tweeted on Thursday night: “After my conversation with Theresa May, our positions remain far away. My government will always defend the interests of Spain. If there are no changes, we will veto Brexit.”

May is due to meet Juncker again on the eve of the summit, at 6 p.m. (1700 GMT) on Saturday - in principle to agree that the absolutely final text is ready for EU leaders to sign.

With Spain, France and other EU member states lobbying for various national vested interests in that political declaration - a 26-page wishlist on future trade and security ties separate from the 585-page withdrawal agreement - there was concern in Brussels that haggling could get out of hand and derail Sunday’s tightly choreographed formal summit of the 27 leaders with May.

Slideshow ( 10 images )

While the withdrawal agreement only requires a qualified majority not unanimity, the EU always seeks consensus on such sensitive matters.

PARKED

EU sources told Reuters that other demands from governments would now be parked in a separate page or two of short text to be endorsed at the summit. French calls for access to British fishing grounds and insistence that post-Brexit Britain follow EU environment, tax, labor and industrial rules are largely drafted, leaving a gap for Spain’s concerns that Madrid be given an effective veto over applying any future deal to Gibraltar.

Slideshow ( 10 images )

EU diplomats said they hoped Spain could accept a statement, similar to one made before the withdrawal negotiations, that nothing in a future EU-UK treaty would apply to Gibraltar unless Madrid consented to that after bilateral talks with London.

The main text of the political declaration said the EU and Britain “agree to develop an ambitious, wide-ranging and balanced economic partnership.

“This partnership will be comprehensive, encompassing a free trade area as well as wider sectoral cooperation ... will be underpinned by provisions ensuring a level playing field.”

Crucially for May, it commits the EU to looking for ways to avoid triggering a “backstop” clause intended to ensure the Irish border remains free of customs checks. Those include, it says, technical and administrative means favored by May’s Brexiteer allies that could limit Britain’s need to keep its broader economic and trade rules in line with the continent.

The text said the post-Brexit relationship would respect “the integrity of the Union’s Single Market and the Customs Union as well as the United Kingdom’s internal market, and recognize the development of an independent trade policy by the United Kingdom beyond this economic partnership”.

The former point deals with EU concern that Britain is using the Irish question to get special access to the EU market while dispensing with its regulations. The latter point responds to complaints from May’s key parliamentary allies in Northern Ireland that the EU plan to avoid a hard border with EU-member Ireland could isolate the province from the British mainland.

However, a lawmaker from the Northern Irish Democratic Unionist Party that props up May’s minority government said later on Thursday that she should ditch her agreement to the backstop if she was to keep DUP support.

Both sides need an accord to keep trade flowing between the world’s biggest trading bloc and the fifth largest national economy. But May has struggled to untangle nearly 46 years of membership without damaging trade or upsetting the lawmakers who will ultimately decide the fate of any deals she secures.

Despite the hopes of financial firms in London, Britain secured no improvements to its proposed future trading relations in financial services, one of the UK’s most important export sectors.

May updated her cabinet on the state of talks by teleconference but her spokesman cautioned that no final deal could be agreed ahead of the EU summit on Sunday. In practice, however, EU leaders who will meet for an hour before they see May want all negotiating finished beforehand.

The transition period, currently due to end after 21 months in December 2020, can be extended for up to two years. May has said it must end before a British election due in mid-2022.