BOSTON — Massachusetts cannot retroactively post information about thousands of registered Level 2 sex offenders on the Internet, the state’s highest court ruled Wednesday.

The unanimous decision came in response to a challenge to a law passed last July that allowed the state to add Level 2 sex offenders to its online database. The state’s Sex Offender Registry Board had previously been allowed to make information available on its website only about Level 3 offenders, those considered the most dangerous and most likely to commit new crimes.

The Supreme Judicial Court did not strike down the new law, but ruled that it could not be applied retroactively to sex offenders who had already been classified as Level 2 prior to the date the law took effect. Level 2 offenders are considered to pose a moderate degree of danger to the public.

Shortly after passage of the law, the Committee for Public Counsel Services, representing several Level 2 sex offenders, got a preliminary injunction from a judge blocking the state from posting information about the more than 6,000 individuals who had received Level 2 classifications prior to July 12, 2013.

The justices, in making the injunction permanent, said making the law retroactive “would be unreasonable and inequitable, and therefore unconstitutional as a violation of due process.”

Residents can obtain information about Level 1 or Level 2 sex offenders from their local police departments.