A divided Supreme Court on Monday said states may not impose on juvenile murderers mandatory life sentences without the possibility of parole.

The 5 to 4 ruling said such mandatory sentences offend the constitution’s prohibition of cruel and unusual punishment, and follow a trend at the court of treating even the worst juvenile offenders differently from adults.

Justice Elena Kagan, writing for the majority, said the decision was consistent with the court’s past findings that children lack maturity and have an underdeveloped sense of responsibility; that they are more vulnerable to outside pressure and that their character is less formed and more open to rehabilitation.

“Our decisions rested not only on common sense — on what ‘any parent knows’ — but on science and social science as well,” Kagan wrote, adding “the mandatory penalty schemes at issue here prevent the sentencer from taking account of these central considerations.”

The decision said judges may still sentence juveniles convicted of murder to a life sentence without possibility of parole, but must take into consideration mitigating circumstances.

The opinion was joined by Kagan’s fellow liberal justices, Ruth Bader Ginsburg, Stephen G. Breyer and Sonia Sotomayor, as well as by Justice Anthony M. Kennedy, who most often sides with conservatives but has authored the court’s previous opinions about juvenile offenders.

It drew sharp rebukes from the court’s conservatives, including Justice Samuel A. Alito Jr., who said from the bench that the ruling represented an “elite vision” from the court that it knows better than the states, 29 of whom authorize mandatory sentences for juvenile murders.

Chief Justice John G. Roberts Jr., in a dissent joined by Alito and Justices Antonin Scalia and Clarence Thomas, elaborated.

“Determining the appropriate sentence for a teenager convicted of murder presents grave and challenging questions of morality and social policy,” Roberts wrote. “Our role, however, is to apply the law, not to answer such questions.”

He said mandatory life sentences “could not plausibly be described” as unusual when a majority of states endorse them.

In 2005, the court banned the death penalty for juveniles who kill, saying “the punishment of life imprisonment without the possibility of parole is itself a severe sanction, in particular for a young person.”

In 2010, the court continued the trend by saying juveniles whose crimes did not include murder could not be sentenced to life in prison without the possibility of parole at some point.

Kennedy wrote both opinions for the divided court.

The cases at the court were brought by lawyers for the Equal Justice Initiative in Montgomery, Ala., which had asked the court to ban life sentences for juveniles 15 and younger when they committed their crimes.

Kagan said the ruling does not address that issue; she expected such cases would be rare when judges were free to take a juvenile’s age into account at sentencing.

“The court took a significant step forward by recognizing the fundamental unfairness of mandatory death-in-prison sentences that don’t allow sentencers to consider the unique status of children and their potential for change,” said EJI’s Bryan Stevenson. “The court has recognized that children need additional attention and protection in the criminal justice system.”

There are 2,300 inmates serving life-without-parole sentences for murders committed before they were 18. But only 79 nationwide were 14 or younger at the time of their crimes, and about 90 percent of those are serving mandatory sentences.

The cases before the justices came from two 14-year-olds who were sentenced to life without parole for their roles in separate killings.

Evan Miller, a victim of abuse so severe that, his lawyer said, he had tried to kill himself five times, was convicted along with another juvenile of killing a neighbor, 52-year-old Cole Cannon, and setting afire Cannon’s trailer in Lawrence County, Ala.

Kuntrell Jackson of Blytheville, Ark., was with two other youths who attempted to rob a video store. One of the others used a sawed-off shotgun to kill 28-year-old clerk Laurie Troup.

The two cases are Miller v. Alabama and Jackson v. Hobbs.

Robert Barnes has been a Washington Post reporter and editor since 1987. He has covered the Supreme Court since November 2006.

Comments our editors find particularly useful or relevant are displayed in Top Comments, as are comments by users with these badges: . Replies to those posts appear here, as well as posts by staff writers.

To pause and restart automatic updates, click "Live" or "Paused". If paused, you'll be notified of the number of additional comments that have come in.

Comments our editors find particularly useful or relevant are displayed in Top Comments, as are comments by users with these badges: . Replies to those posts appear here, as well as posts by staff writers.