The EU's top court has upheld the right of Commonwealth citizens in Gibraltar to vote in European elections.
Gibraltarians first voted in a European election in 2004
The judges dismissed a case brought by Spain last year, which argued that only EU citizens could legally vote.
They also said it was legal for residents of Gibraltar to vote as part of the UK's south-west European constituency, as they have since 2004.
Neil Parish MEP said the court had thrown out a "petty" Spanish attempt to disenfranchise Commonwealth citizens.
The European Court of Justice said EU rules did not define precisely who was entitled to vote in elections to the European Parliament, so it was up to the member states to decide.
"The relevant articles of the EC treaty do not preclude the Member States from granting that right to vote and to stand as a candidate to certain persons who have close links to them, other than their own nationals or citizens of the Union resident in their country," the ruling said.
Spain brought the case as part of a long-running dispute over ownership of Gibraltar.
As well as arguing that it was illegal for non-EU citizens to vote, it said the UK broke European law by combining Gibraltar with an existing UK constituency.
The UK was obliged to give Gibraltarians a chance to vote in European elections after a different court, the European Court of Human Rights (ECHR), said that it was violating their rights by excluding them.
Citizens of Commonwealth countries resident in Britain have the right to vote in all elections in the UK, and the 2003 European Parliament Act extended this right to citizens of Gibraltar in order to comply with the ECHR ruling.
Mr Parish, a Tory MEP for the south-west constituency, said the new ruling from the European Court of Justice was "absolutely right" to recognise the UK's right to decide who should vote in elections.
"It is a principle that goes right to the heart of our democracy," he said.
"I hope Spain will now stop its bitter sniping at Gibraltar."