Spain will revive its bid for shared sovereignty over Gibraltar once Britain has left the European Union, the country's prime minister has said, adding Madrid had the support of the bloc to resolve the 300-year-old dispute.

Speaking after an EU leaders' summit, Pedro Sanchez said Spain's position over Gibraltar, a British territory since 1713, was stronger after the agreement of a Brexit because Spanish policy effectively became EU policy.

"We are going to resolve a conflict that has been going for over 300 years," Mr Sanchez told a news conference, adding he had said the same thing to British Prime Minister Theresa May, who met the EU's 27 leaders to endorse the withdrawal treaty that she will now put to the British parliament.

Asked if Spain would seek a discussion over joint sovereignty once Britain leaves the bloc on 29 March, 2019, Mr Sanchez said: "We will discuss all issues."

The small peninsula attached to Spain is a major point of contention in Anglo-Spanish relations. Spain has long claimed sovereignty.

Gibraltar residents rejected shared sovereignty with Spain in a referendum in 2002. "The Rock", as it is known by locals, is due to leave the EU along with the United Kingdom.

Mrs May has said that "Gibraltar is British" and that when she negotiated for Britain, she did so for the territory, but declined to go into more details.

However, given that 96% of its population voted in Britain's 2016 referendum to remain in the EU, the mood was now different, Spanish officials said.

"This puts Spain in a position of strength in negotiations with the United Kingdom over Gibraltar that we have not had until now," Mr Sanchez told reporters after the summit.

He was referring to a 1986 agreement when Spain joined the bloc and had to adapt its Gibraltar policy to British policy within the EU.

He said that situation was now being reversed, a view also shared by many in the bloc, one EU official said.

Signalling such support, European Commission President Jean-Claude Juncker said many Europeans did not realise the importance of Gibraltar for Spain.

"We all lose (with Brexit), especially the United Kingdom, but regarding Gibraltar, Spain wins," said Mr Sanchez, who made no attempt to hide his delight during the news conference.