David Cameron was last night given a six-month deadline to draw up plans to allow prisoners to vote.
The ruling by the European Court of Human Rights will increase the animosity among many Tory MPs towards European institutions and leaves ministers with a dilemma over how to respond.
The ECHR delivered its ultimatum after it dismissed the Government's final appeal against being forced to extend the vote to offenders.
David Cameron had said plans to enfranchise prisoners made him feel "physically sick" and two months ago MPs voted by 234 to 22 votes - a majority of 212 - to retain 140-year-old ban.
The Government has been given until October to produce "legislative proposals" to end the blanket ban on inmates voting in national and European elections.
The Government had originally suggested allowing priosners serving sentences of up to four years to vote in order to comply with an ECHR ruling that a total ban was illegal. But that option has come under fierce opposition from all sides of the parties.Ministers have warned that the Government could face possible compensation claims running into millions from inmates if it fails to comply.
One possibility is that they will suggest allowing prisoners on sentences of a year or less to vote. But it is unclear whether that would comply with the ECHR ruling and would still infuriate many MPs.
In November the Court awarded two UK prisoners 5,000 euro (£4,350) in costs and expenses for their loss of voting rights, which was ruled a breach of their human rights. More than five years ago it delivered a similar verdict in a separate case brought by a prisoner, but the then Labour government left the blanket ban in place and delayed a decision on the issue until after last year's election.
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.
The human rights judges are not insisting that all prisoners have the right to vote. That leaves the Government free to decide how to implement voting rights, for example by offering the right to vote to prisoners serving relatively short sentences, while maintaining a ban for long-term prisoners jailed for more serious crimes.