Britain says it reached agreement during overnight talks with the European Commission on the draft text of a political declaration laying out the terms for Britain’s “smooth and orderly” exit from the European Union.

Prime Minister Theresa May announced the agreement, which must be approved by EU leaders Sunday, in front of her No. 10 Downing Street residence early Thursday.

She said the deal “delivers” on the will of the British people as expressed in a divisive Brexit referendum in June 2016. “It brings back control of our borders, our money and our laws, and it does so by protecting our jobs, protecting our security and protecting the integrity of the United Kingdom.”

Addressing parliament later in the day, May said the British people “want Brexit to be settled. They want a good deal that sets us on a course for a brighter future. 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.”

The overnight talks followed a meeting Tuesday between May and Jean-Claude Juncker, president of the European Commission. May said the two instructed their negotiating teams to work through the night if necessary to reach an agreement.

The deal must still be approved by the leaders of the individual EU states at a special EU Council meeting on Sunday. May also faces a challenge in getting the Brexit agreement through her own parliament, where many members feel it does not go far enough to break ties with the continent.

A last-minute complication arose this week when the Spanish government threatened to veto any agreement unless it received assurances on future negotiations over Gibraltar, a British outpost that Spain sees as rightfully part of its territory.

In her statement to reporters, May said she had spoken Wednesday evening to Spanish Prime Minister Pedro Sanchez and is “confident that on Sunday we will be able to agree a deal that delivers for the whole United Kingdom family, including Gibraltar.”

Several other EU governments objected to earlier outlines of the deal because they believe it gives Britain a competitive advantage by not tying it closely enough to EU regulations, workers’ rights, and environmental standards, potentially lowering the production costs of British goods.

The results of May’s Brussels trip didn’t appear to sway a skeptical parliament, where she received as many hostile questions from her own lawmakers as she did from opposition MPs.  There are no signs the deal will win the approval of the House of Commons, where opposition parties oppose it, as well up to 100 Conservative Brexit hardliners and and a Northern Ireland party May relies on to govern.

British critics of the deal believe it binds Britain too closely to Europe-wide regulations while leaving it with no say in formulating those directives. They also have objected to proposed language that would bar Britain from negotiating trade pacts with other countries.

A major concern throughout the negotiations has been how to maintain a free flow of goods between Northern Ireland, which is part of Britain, and the Republic of Ireland which is an EU member. The opening of that border helped to end decades of conflict between partisans of the two populations.

May’s Brussels trip resulted in the expansion of the political declaration that accompanies the 585-page divorce deal. It increased from five pages to 26 and sets out the parameters of a possible future free trade that will take years to negotiate.

But there are still no signs that the deal will win the approval of the House of Commons, where the opposition parties oppose it as well up to 100 Conservative Brexit hardliners and a Northern Ireland party she relies on to govern. The results of her Brussels trip didn’t appear to sway a skeptical parliament, where she received as many hostile questions from her own lawmakers as she did from opposition MPs.

VOA’s Jamie Dettmer contributed to this report.