– Nothing is simple in Brexitland.

In the lead-up to a historic summit Sunday in Brussels, where a Brexit deal is expected to be rubber-stamped, tiny Gibraltar suddenly loomed large.

It literally put Britain’s European Union divorce settlement between “The Rock” and a hard place for a time. That’s because Spanish Prime Minister Pedro Sanchez insisted his country have final say over any future status of the enclave, a self-governing British territory on the tip of southern Spain and near the narrow mouth of the Mediterranean.

Spain, which has had a centuries-long feud with Britain over Gibraltar, wanted Britain to make a commitment in ­writing before the summit. It went down to the wire. Late Saturday, Sanchez said it would lift its veto because the Europe Union and the Britain had accepted Spain’s demands. The summit, he said, could go ahead now that he had received written assurances that meant that in the future Madrid and London could directly negotiate on Brexit issues relating to Gibraltar.

The Brexit package, which is very much British Prime Minister Theresa May’s deal, has been painstakingly crafted. But it’s been a tortured path: 17 months of sometimes bitter negotiations, nonstop bickering within May’s own leadership team, ongoing concerns about how to handle the border between E.U.-member Ireland and North Ireland, the resignation of a string of ministers including two Brexit secretaries, and a new vocabulary of Brexit-related puns and put-downs from British tabloids.

Around 30,000 Britons live in Gibraltar, a 2.6-square mile outpost that shares a border with Spain. It was famously the headquarters for Gen. Dwight D. Eisenhower during the planning stages of the Allied invasion of North Africa in 1942.

The sovereignty issues around Gibraltar may have hit the headlines this week, but they are long-festering. Gibraltar was ceded to Britain in 1713 under the Treaty of Utrecht, but it is still claimed by Spain. In a 2002 referendum, its citizens overwhelming rejected a proposal of joint British-Spanish rule, instead opting to remain under the sovereignty of Britain only. But the two countries have deep ties — an estimated 12,000 workers cross the border every day. In the 2016 E.U. referendum, Gibraltarians voted 96 percent to remain in the European Union.

May has said that any Brexit deal must apply to the “whole U.K. family,” including Gibraltar.