Britain should think about sharing sovereignty over Gibraltar with Spain to help solve the problem of the territory being excluded from the EU against its will, Peter Hain, the former Labour cabinet minister, has said.

Hain, who tried to negotiate such an agreement in 2002, called on the government to think about “resurrecting co-sovereignty” as it would give Gibraltarians much more freedom and security than they have previously enjoyed.

“The co-sovereignty deal was and still could be a win-win for all parties to the dispute,” he wrote in the Guardian. “The only concession Gibraltarians would have to make is a Spanish flag flying on the Rock alongside a British one. Their cherished British citizenship, traditions, customs and way of life would be unchanged – except for the better, because being under siege from Spain would disappear.

“Pints of beer would still be served in British-style pubs. Gibraltarians would keep their institutions – self-government, an elected House of Assembly, courts and police service.”

It's surely time to dust down the files and for politicians in Gibraltar, Britain and Spain to show real leadership

Peter Hain

The Labour peer made the proposal after a week of diplomatic tensions prompted by the EU’s draft negotiating guidelines, which proposed giving Spain a veto over the future of Gibraltar in any deal that emerges after Brexit.

The situation escalated when Michael Howard, a Conservative peer and former Tory leader, suggested that Theresa May would show the same resolve over Gibraltar as Margaret Thatcher did when defending the Falklands, injecting the issue of possible war into the debate.

May has tried to defuse the row by saying the solution was “jaw-jaw” with Spain rather than war, but tensions surfaced again when the Royal Navy ordered a Spanish warship out of the peninsula’s disputed territorial waters.

Hain suggested that tensions on both sides could be cooled by discussions on Gibraltar, with a sovereignty agreement like the one governing Andorra, in which the president of France and bishop of Catalonia are “co-princes” of the principality.

The Labour peer was Europe minister in 2002, when he nearly managed to get the deal signed off, before Spain got cold feet over the agreement, he said.

“Resurrecting co-sovereignty today would doubtless provoke a similar reaction on the Rock even though it’s in a very much worse place than 15 years ago because of likely exclusion from the European Union very much against its will. Yet it would give Gibraltarians much more freedom and security than ever historically,” he said.

Peter Hain, former Labour cabinet minister, tried to negotiate a co-sovereignty agreement between Britain and Spain in 2002. Photograph: John Stillwell/PA

“It’s surely time to dust down those files, and for politicians in Gibraltar, Britain and Spain to show some real leadership.”

The issue of Gibraltar was repeatedly brought up in a European parliament debate on Wednesday, in which MEPs voted overwhelmingly in favour of a tough negotiating stance towards the British government in the Brexit negotiations. They repeatedly cited the rows over claims that May had tried to blackmail the EU by threatening to weaken security cooperation and Howard’s comments suggesting that the UK would be prepared to go to war over Gibraltar.

Esteban González Pons, a key ally of the Spanish prime minister, said: “Just seven days after Brexit, we are hearing outbursts of racism and some members of parliament are talking about war … Unfortunately, the UK has chosen the wrong road in history.

“You have got it wrong , you are going to commit self-harm while at the same time harming all of us … I hope you think again and get it right. I hope you won’t be blinded by arrogance.”

The parliament’s motion also backed making the European court of justice responsible for settling any legal challenges during the transition period, and is opposed to a special deal for the City of London.

However, the EU’s chief negotiator, Michel Barnier, said the European parliament – as the first EU institution to respond to May’s letter and the institution that will ultimately be asked for its consent on a deal – had set the tone for the talks.

Speaking to MEPs during the debate that preceded the vote, Barnier said it was not a ruse on the part of the EU to insist on dealing with the UK’s divorce bill first, but an essential precondition for success. “A single financial settlement, as a result of UK commitments to the EU, and the EU commitments to the UK – there your resolution is very clear. We do not seek to punish the UK, but simply ask the UK to deliver on its commitments and undertakings as a member of the EU.”

Addressing the former Ukip leader, Nigel Farage, who earlier in the debate accused the EU of behaving like the mafia in making “impossible demands”, Barnier said: “In fact, Mr Farage, all we are doing is settling the accounts, no more, no less.”