“We need to reach an agreement on Gibraltar by mid-October,” Sanchez told reporters after meeting his EU counterparts at an informal summit dominated by Brexit and migration.
“We have still some complications but I think that the willingness of the British government and the Spanish government is to reach an agreement,” Sanchez said.
In April 2017 the EU agreed to give Spain the right to veto any future post-Brexit relationship between the 27-member bloc and Gibraltar.
The territory has been under British control since 1713 but Madrid has long wanted it back.
Spain has nevertheless tried to reassure the territory's inhabitants that it will put the issue of sovereignty aside and won't use the negotiations over Gibraltar to try to get the territory back or to make their lives more complicated.
However, Sanchez said disagreements remained around the perennial Spanish accusations that Gibraltar acts as a tax haven and worries over tobacco smuggling over the border.
“We have some differences on environmental cooperation, judicial and policial cooperation, free movement, tobacco, and taxes,” Sanchez said.
“It is not everything. We are very close to reaching an agreement,” he added.
After a meeting in Madrid with Michel Barnier, the EU’s Brexit negotiator, Josep Borrell, Spain’s foreign minister, said that Spain was “going to use the Brexit negotiation to obtain the most positive things possible for our people, for Spain and for the Spaniards who work in Gibraltar.”
Mr Barnier tweeted his full support following the meeting.
“Full support for Spain in its negotiations w/ UK on #Gibraltar, which need to conclude asap”.
In Madrid today, cordial meeting with @sanchezcastejon to prepare for #Brexit #Salzburgsummit18. A deal with #UK is possible if integrity of Single Market is preserved. Full support for Spain in its negotiations w/ UK on #Gibraltar, which need to conclude asap. pic.twitter.com/lEhR65DSdK
— Michel Barnier (@MichelBarnier) September 17, 2018