WASHINGTON – The Supreme Court ruled Monday that juveniles may not be sentenced to life imprisonment without the possibility of parole unless guilty of homicide, declaring unconstitutional a sentencing practice that has been adopted by some states but, the court said, was “rejected the world over.”

The court ruled 5-4 that locking up forever those younger than 18 who have not killed anyone violates the Constitution’s ban on cruel and unusual punishment.

The decision follows the court’s 2005 ruling that juveniles may not be executed and expands upon its decision that the Eighth Amendment must be interpreted in light of the country’s “evolving standards of decency.”

Justice Anthony Kennedy, writing for the majority, said states must provide juveniles who receive long sentences a “meaningful” chance to eventually show they should be released.

“By denying the defendant the right to re-enter the community, the state makes an irrevocable judgment about that person’s value and place in society,” Kennedy wrote. “This judgment is not appropriate in light of a juvenile nonhomicide offender’s capacity for change and limited moral culpability.”

The case at hand involved Terrance Jamar Graham, who was convicted of robbery in Jacksonville, Fla., when he was 16. He received probation but was arrested again at 17 for taking part in a home invasion. The judge in the case then sentenced him to life in prison without the possibility of parole.

Kennedy said there were 129 juvenile nonhomicide offenders serving sentences of life without parole in 11 states, including Virginia. The vast majority of them — 77 — are in Florida.

Life without parole sentences for juvenile offenders are allowed but not currently used in Maine and eight other states, according to The Sentencing Project, a nonprofit that advocates for criminal justice reform.

Kennedy was joined by the court’s liberal wing: Justices John Paul Stevens, Ruth Bader Ginsburg, Stephen Breyer and Sonia Sotomayor.

Chief Justice John Roberts joined them in rejecting the outcome of Graham’s case, saying the sentence was harsh given the crime. But he did not join the opinion that the sentence of life without parole is always unconstitutional.

“Some crimes are so heinous, and some juvenile offenders so highly culpable, that a sentence of life without parole may be entirely justified under the Constitution,” Roberts wrote.

Justice Clarence Thomas wrote a stinging dissent, saying the majority’s interpretation of the Eighth Amendment is “entirely the court’s creation.”

“The court is quite willing to accept that a 17-year-old who pulls the trigger on a firearm can demonstrate sufficient depravity and irredeemability to be denied re-entry into society, but insists that a 17-year-old who rapes an 8-year-old and leaves her for dead does not,” Thomas wrote.

“The question of what acts are ‘deserving’ of what punishments is bound so tightly with questions of morality and social conditions as to make it, almost by definition, a question for legislative resolution.”

His dissent was joined in full by Justice Antonin Scalia and in part by Justice Samuel Alito.

“This is a significant victory for children. The court recognized that it is cruel to pass a final judgment on children, who have an enormous capacity for change and rehabilitation compared to adults,” said Bryan Stevenson, executive director of the Equal Justice Initiative.

“I am very encouraged by the court’s ruling. It’s an important win not only for kids who have been condemned to die in prison but for all children who need additional protection and recognition in the criminal justice system.”

Stevenson had represented another Florida youth, Joe Sullivan, who was sentenced to life in prison without parole for a rape committed at 13.

The court heard the Sullivan case but dismissed it Monday because of procedural problems. Sullivan will probably be able to challenge his sentence, however, because of the ruling in Graham v. Florida.