The supreme court is siding with a Muslim prison inmate in Arkansas who sued for the right to grow a short beard for religious reasons.

The court’s unanimous ruling on Tuesday in a case about religious liberty stands in contrast to the Hobby Lobby case that bitterly divided the justices in June over whether family-owned corporations could mount religious objections to paying for women’s contraceptives under the healthcare overhaul.

The justices said that inmate Gregory Holt could maintain a half-inch beard because Arkansas prison officials could not substantiate claims that the beard posed a security risk.

Holt said that he has a right to grow a beard under a federal law aimed at protecting prisoners’ religious rights. The law is similar to the Religious Freedom Restoration Act that the court said in a 5-4 ruling in late June could be invoked by business owners who object to paying for contraceptives.

This time around, the Obama administration, religious groups and atheists alike backed Holt, also known as Abdul Maalik Muhammad. More than 40 states allow inmates to keep beards.

Justice Samuel Alito said in his opinion for the court that Arkansas can satisfy its security concerns in some other way when “so many other prisons allow inmates to grow beards while ensuring prison safety and security”.

Holt is serving a life sentence for a brutal assault on his girlfriend and is being held at a maximum security prison 80 miles south-east of Little Rock. His case first came to the court’s attention when he filed a handwritten plea to the court asking it to block enforcement of Arkansas’s no-beard rule.

Holt argued in court papers that his obligation to grow a beard comes from hadiths, accounts of the acts or statements of the Prophet Muhammad. In one statement attributed to the prophet, Muslims are commanded to “cut the mustaches short and leave the beard”.

Holt said he understands that statement to mean he should grow a full beard, but offered a half-inch beard as a compromise because California allows Muslim inmates to wear beards of that length.

Alito wrote that the prison’s “interest in eliminating contraband cannot sustain its refusal to allow petitioner to grow a half-inch beard”.

Holt said the state’s prison grooming policy prohibiting inmates from having facial hair other than a “neatly trimmed mustache” violated his religious rights under a 2000 federal law called the Religious Land Use and Institutionalised Persons Act. Holt’s lawyers noted that more than 40 states and the federal government allow prison inmates to have similar beards.

Holt is serving his life sentence – for domestic battery and burglary – at the Varner Supermax prison, according to the Arkansas department of correction.