WASHINGTON — Some teenage murderers may eventually gain their freedom, as a divided Supreme Court on Monday struck down mandatory life sentences without parole for juveniles convicted of capital crimes.

In a pair of horrific cases arising out of two Southern states, the court by a 5-4 vote concluded that a mandatory sentencing rule that sends teenage convicted killers to prison without possibility of parole amounted to cruel and unusual punishment.

“In imposing a state’s harshest penalties, a sentencer misses too much if he treats every child as an adult,” Justice Elena Kagan wrote for the majority. “Mandatory life without parole for a juvenile precludes consideration of his chronological age and its hallmark features; among them, immaturity, impetuosity and failure to appreciate risks and consequences.”

The ruling undercuts laws in 28 states and in the federal government that impose mandatory life-without-parole sentences for juveniles as well as adults convicted of certain forms of murder. The ruling also provoked a sharply worded set of dissents from conservative justices who warned ominously that the public will now be at greater risk.

More than 2,500 individuals are serving life without parole for murders committed when they were under 18. About 2,100 of them were convicted in states with mandatory life sentences; these are the inmates who now eventually could be freed.