The Supreme Court ruled unanimously Tuesday that Arkansas must allow a Muslim prisoner to grow a beard that he says his religion requires.

Justice Samuel A. Alito Jr., writing for the court, said Arkansas prison officials had violated a federal law passed to protect religious practices from policies set by state and local officials.

Alito said the Religious Land Use and Institutionalized Persons Act does not require a prison to grant religious exemptions simply because a prisoner asks or because other prisons do. But he said Arkansas officials offered no evidence that a short beard presented security risks or could serve as a hiding place for contraband, as the officials once argued.

“The same is true of an inmate’s clothing and shoes” and hair on the head, Alito wrote. “Nevertheless, the Department does not require inmates to go about bald, barefoot, or naked.”

Alito said Arkansas had not overcome the high hurdles set by the law: that policymakers may not burden a person’s exercise of religion unless they can show a compelling governmental interest and that the policy was the least-restrictive means of achieving that goal.

This undated photo provided by the Arkansas Department of Correction shows prison inmate Gregory Holt. (AP)

The same kind of issue arose last year in one of the court’s most controversial rulings: that the contraceptive coverage mandate in the Affordable Care Act failed essentially the same compelling-interest test under a related law, the Religious Freedom Restoration Act. The court’s conservatives prevailed in that case on a split 5-to-4 vote.

But in the recent case, brought by inmate Gregory Houston Holt, practically all religious and public-interest groups were united in backing the prisoner, and the court’s decision was unanimous.

Justice Ruth Bader Ginsburg, in the minority in Burwell v. Hobby Lobby , explained what she found different between the cases in a concurring opinion.

Unlike with the objecting business owners who did not want to provide employees with contraceptives that violated the owners’ religious beliefs, Ginsburg said accommodating Holt’s request “would not detrimentally affect others who do not share petitioner’s belief.”

Holt is serving a life sentence for slitting the throat of a former girlfriend and stabbing her in the chest. He is also known as Abdul Maalik Muhammad, and according to his brief to the court, he thinks his Muslim faith requires him to follow this dictate: “Allah’s Messenger said, ‘Cut the moustaches short and leave the beard (as it is).’ ”

Holt said he was willing to compromise with prison officials and keep his beard trimmed to one-half inch. But Arkansas corrections officials allow beards only for dermatological conditions, not religious beliefs, and even then they must be trimmed to one-quarter inch.

Lower courts had ruled that deference to prison officials required them to uphold Arkansas’ restrictions, even though a magistrate said it was “preposterous” to believe that contraband could be hidden in a short beard.

But Alito wrote that deference requires evidence of the policy’s importance and evidence that it is the least restrictive means of achieving its goal.

At oral argument in October, Alito was the most persistent questioner of the Arkansas policy. As a lower-court judge, he once wrote an opinion that said Muslim police officers had a right to grow beards.

The federal prison system and most states already offer such beard accommodations, and the Obama administration supported Holt.

The case is Holt v. Hobbs.