Read more news from CNN

UK and Spain reach agreement over Gibraltar, paving way for Brexit deal

London(CNN) The UK and Spain reached an agreement Saturday over the status of Gibraltar once the UK has left the European Union.

The accord over the British territory paves the way for approval by 27 EU governments at a summit Sunday on the withdrawal terms of the UK from the bloc next year.

"I have just told the head of state, the King, that Spain has reached an agreement over Gibraltar," Spanish Prime Minister Pedro Sanchez told reporters in Madrid.

He said the agreement excludes the territory from the general negotiation between the EU and UK and "will allow Spain to negotiate directly with the UK over Gibraltar."

Spain "will vote tomorrow in favor of Brexit," Sanchez said.

Gibraltar, a rocky outcrop that adjoins the southern coast of Spain, voted overwhelmingly to remain in the EU. It is surrounded by the Spanish region of Andalusia that will soon hold regional elections, and Spain's territorial claim to Gibraltar threatened to scupper Sunday's summit.

"The unwavering commitment of the UK that it will negotiate future trade and other arrangements with the EU that work for all of the British family of nations, including Gibraltar," the government of Gibraltar said in a statement.

"Throughout our history we've stuck with Britain," said Fabian Picardo, the chief minister of Gibraltar.

The deal of the terms of withdrawal is opposed by the minority partner in the UK government, the Democratic Unionist Party.

Historic mistake

Speaking at a DUP conference Saturday, Boris Johnson, the former UK foreign minister and a leading Brexiter, said the UK was "on the verge of making a historic mistake" and that the UK would become "rules-takers."

"Brussels has got us exactly where they want us -- a satellite state," he said.

May agreed to accept the terms of the customs union and the regulations of the EU's single market in the agreement she reached with the European Commission earlier this month. Critics like Johnson say this is the worst possible scenario for Britain.

Theresa May has refused to comment on whether she will resign if she loses the parliamentary vote on Brexit.

Nothing in the tortured 17-month withdrawal process since the UK voted to leave the EU in June 2016 has gone smoothly, and the contested rock of Gibraltar was just the latest snag.

At the moment, the border between Spain and Gibraltar is open, but the Spanish government was concerned that would change after Brexit, affecting future trade negotiations. Spain joined the EU in 1986, 13 years after the UK, and one of the conditions of its accession treaty was a clause that agreed to the British sovereignty over the outcrop with a population of 30,000.

Under EU rules, the Brexit treaty must be approved by a "strong qualified majority" of the 27 remaining nations. Even though Spain cannot formally veto the legally binding part of the agreements, other EU governments would be reluctant to adopt it without a consensus.

Even if the agreement is approved by EU leaders on Sunday, it will still need to be voted through the UK Parliament, a ballot that is far from secured for May.

Outbrain