The judges ruled by 16 to 1 that there had to be a possibility of release and review of the sentence in order for it to remain compatible with the European Convention on Human Rights.

Prime Minister David Cameron said he “profoundly disagrees with the Court’s ruling”.

Justice Secretary Chris Grayling said the human rights convention’s authors would be “turning in their graves”.

He told the BBC: “I don’t believe that the people who wrote that convention ever imagined that it would stop a judge saying to a really evil offender – ‘you’ll spend the rest of your life behind bars’.

“It reaffirms, to me, my own determination to bring real changes to our human rights laws and to see a real curtailing of the role of the European Court in this country.”

Home Secretary Theresa May told MPs the public would be “dismayed” by the ruling.

The government cannot appeal against the judgment, which applies in England and Wales, but now has six months to consider its response.