Masood Syed loved his job as a police officer in the US’s most diverse city.

As a Muslim, he was also very attached to his beard.

This week, the 32-year-old found himself at the centre of legal battle after a judge ordered the New York Police Department (NYPD) to reinstate the officer after he had been suspended for 30 days over his beard.

Masood Syed said he felt humiliated when he was escorted from his office (AP)

On Monday, Mr Syed had been suspended from work and escorted from the department’s headquarters after it was deemed that his beard was more than 1mm in length and therefore breached regulations. Mr Syed said he had worn a 1-inch beard for most of his 10-year career, and had only occasionally drawn critical comments.

On Wednesday, a judge ruled that the force reinstate Mr Syed and pay him any money or benefits that had been withheld. US District Judge Kevin Castel criticised the city and issued a restraining order to allow Mr Syed to work until another hearing on July 8.

“I am very relieved,” Mr Syed told CBS, after the ruling, as he celebrated his 32nd birthday.

Brooklyn patrol officer Rohail Kahlid, who has a beard about a half-an-inch long, said that enforcement of the rule could often be arbitrary.

“It becomes an issue on and off. It depends on who’s the boss,” he said,

Mr Syed, who is of Pakistani heritage, said two uniformed supervisors escorted him from his office where he works as a law clerk to administrative judges, sometimes preparing legal documents for the police commissioner about disciplinary issues. “It was extremely humiliating,” he Syed. “I felt insulted, frankly.”

He said he hoped his lawsuit, which seeks class-action status, would help more than 100 police employees who find the religious exception to the department’s no-beard policy insufficient because they say the length of the beard allowed is not reasonable.

The lawsuit seeks unspecified financial damages and a court order banning the NYPD from enforcing its beard policy until it provides reasonable religious accommodations.

City attorney Michael Fleming said the beard ban was necessary. Besides for religious reasons, exceptions exist for undercover duties and medical conditions. Occupational Health and Safety Administration regulations require annual fit-testing and prohibit respirators for employees with facial hair.

The judge became impatient as he questioned Fleming about the policy and the departments failure to respond to a December 2015 request by 37 police officers for an exception to the no-beard policy.

“The court is troubled by the fact it cannot get an answer,” he said.