The European Court of Human Rights has ruled that Britain cannot ban prisoners from voting, piling pressure on the prime minister who last year said the idea made him "physically ill".
Human rights judges have now given the government six months to honour the coalition pledge to give prisoners the vote, following a case in Italy where an Italian man won his appeal against being disenfranchised after his conviction for killing his wife and wounding one of his sons.
The ECHR accepted the UK government argument that "each State [in Europe] has a wide discretion as to how it regulates the ban, both as regards the types of offences that should result in the loss of the vote and as to whether disenfranchisement should be ordered by a judge in an individual case or should result from a general application of a law".
However, the judges added that Tuesday's decision amounted to confirmation of a ruling against the UK in 2005 that a blanket ban on all serving prisoners losing voting rights is a breach of their human rights.
The wrangle with Strasbourg began when UK inmates complained that the loss of voting rights violated a Human Rights Convention Article guaranteeing the "right to free elections".
The court twice decreed the UK's total ban on votes for prisoners to be illegal.
But the Labour government left the ban in place, and Tory inaction despite a second ruling in 2010 angered civil liberties groups.
Last year Minister for Political and Constitutional Reform Mark Harper told the Commons that the coalition reluctantly accepted that the UK had a legal obligation to fall in line, but had not yet decided which inmates it would affect.
Mr Cameron was more direct a day later, telling MPs: "It makes me physically ill to contemplate giving the vote to prisoners. They should lose some rights, including the right to vote."
If the UK complies with the ruling to grant some prisoners voting rights within the new six-month deadline triggered today, the Human Rights Court would strike out all similar pending cases.
That would remove the threat of massive potential government damages payments to prison inmates if all complaints went through the courts and were upheld.
The original UK case on 2005 was a landmark victory for convicted killer John Hirst from Hull.
In the November 2010 case, two prisoners, named as Robert Greens and MT, both serving time at Peterhead prison, were awarded €5,000 in costs and expenses for their loss of voting rights.
About 40% of the 47 countries covered by the Human Rights Convention - including all 27 EU member states - have no restrictions on prisoners voting.
Others ban only some sentenced prisoners from voting. In France and Germany, courts have the power to impose loss of voting rights as an additional punishment.
The UK is among a few European countries, including Armenia, Bulgaria, Estonia, Hungary and Romania, which automatically remove voting rights from sentenced prisoners, although UK remand prisoners still have the vote.
A Downing Street spokeswoman said the government would consider the implications of the ruling for the UK before responding.
The spokeswoman said: "This is a judgment affecting Italy, but clearly we need to consider the implications of that judgment on the issue of prisoner voting for the UK.
"The position for the UK is that the attorney general has argued that the issue of social policy, including prisoner voting, is a matter for parliament and it is for parliament to judge whether and which prisoners should have the vote, and that the court should not interfere with that judgment unless it is manifestly without reasonable foundation."
Juliet Lyon, director of the Prison Reform Trust, said: "People are sent to prison to lose their liberty, not their identity.
"The UK's outdated ban on sentenced prisoners voting, based on the 19th century concept of civic death, has no place in a modern democracy and is legally and morally unsustainable."
She went on: "Experienced prison governors and officials, past and present bishops to prisons and chief inspectors, electoral commissioners, legal and constitutional experts and most other European governments believe people in prison should be able to exercise their civic responsibility.
"The European Court has made clear in today's judgment the UK's legal obligations to overturn the blanket ban."
Paul Nuttall, Ukip member for North East England, said: "This is a bad judgment from a Mickey Mouse court. The Ukip position is there should be a blanket ban of votes for prisoners.
Pass David Cameron the sick bag, because this judgment means that British prisoners will get the vote - some of them at least."
Shadow justice secretary Sadiq Khan said: "Labour has consistently believed that those deprived of their freedom after being given a custodial sentence shouldn't be entitled to vote.
"While we recognise the importance of the European Convention on Human Rights and the European Court of Human Rights, we feel the original decision back in 2004 was wrong, and that's why the Labour government didn't implement it, and we appealed again and again.
"On these kinds of issues, the European court should be giving far more discretion to individual countries and this is an important reform that needs to be implemented."
Suggested For You
SUBSCRIBE AND FOLLOW
Get top stories and blog posts emailed to me each day. Newsletters may offer personalized content or advertisements.Learn more