The 5-4 decision invalidates laws in 28 states that required such sentences for young murderers. More than 2,000 prisoners could now receive new sentences or parole hearings.

WASHINGTON — It is cruel and unusual punishment to send a young murderer to die in prison if a judge has not weighed whether his youth and the nature of his crime merited a shorter prison term, the Supreme Court ruled Monday.

The 5-4 decision struck down laws in 28 states that mandated life terms for juvenile murderers with no hope for parole.

The justices ruled in the cases of two 14-year-old boys, one from Alabama and one from Arkansas, who were given life terms for their roles in homicides. But the decision applies to all those under 18 who are sentenced under mandatory laws.

The ruling could lead to new sentencing or parole hearings for more than 2,000 prisoners around the country who committed homicides when they were young and were given mandatory life terms. The justices set a new constitutional rule that prisoners could cite in their appeals.

Monday's decision does not free any prisoner, and it does not forbid judges in the future from imposing life terms on young killers. But it stands as a potentially far-reaching victory for those who have objected to imposing long prison terms on young offenders.

Speaking for the court, Justice Elena Kagan said the decisions of the last decade had established, or restored, the principle that "children are different" when it comes to criminal punishments.

"Our decisions rested not only on common sense — on what 'any parent knows' — but on science and social science as well," she said. Juveniles are immature and are less deserving of the harshest punishments, she said.

In the case of young people who take part in a homicide, "a judge or jury must have the opportunity to consider mitigating circumstances before imposing the harshest possible penalty," Kagan said. "We therefore hold that mandatory life without parole for those under age 18 at the time of their crimes violates the 8th Amendment's prohibition on 'cruel and unusual punishments.' "

The decision was the third in a decade that puts new constitutional limits on punishments for young criminals. All have come by 5-4 votes, with Kennedy joining the court's liberal bloc. In 2005, the court abolished the death sentence for those under 18 who are convicted of murder. In 2010, the justices went further and said life terms with no parole were unconstitutional for juveniles who commit crimes short of murder.

The pair of cases involving 14-year-olds asked the high court to abolish life prison terms for such young offenders. But the justices opted for a narrower ruling that targeted only mandatory laws.

Chief Justice John G. RobertsJr.dissented. "Put simply, if a 17-year-old is convicted of deliberately murdering an innocent victim, it is not unusual for the murderer to receive a mandatory sentence of life without parole," he said. The fact that 28 states have such laws prove it is not unusual punishment. "Perhaps science and policy suggest society should show greater mercy to young killers.… But that is not our decision to make." Justices Antonin Scalia, Clarence Thomas andSamuel A. Alito Jr. joined in dissent.

Alito also delivered a stinging dissent in the courtroom. He spoke of the "incredibly brutal" crimes perpetrated by 17-year olds, and he accused the majority of exposing "members of society ... to the risk that these convicted murderers, if released from custody, will murder again."

Kagan replied in a footnote that the court's decision did not tell judges to ignore the "most heinous" crimes, but rather to reserve the harshest punishment for such crimes.