BOSTON — An all-girls Catholic prep school in Massachusetts violated state anti-discrimination law by rescinding a job offer to a man in a same-sex marriage, a judge ruled.

Matthew Barrett was offered a job as Fontbonne Academy’s food services director in 2013, but the offer was withdrawn days later after he listed his husband as his emergency contact.

Barrett sued, alleging that the Milton school discriminated against him based on sexual orientation and gender. Norfolk Superior Court Judge Douglas Wilkins agreed, rejecting Fontbonne’s claim that hiring Barrett would infringe on its constitutional rights because it views his marriage to a man as incompatible with its religious mission.

The judge said Barrett’s duties as a food services director did not include presenting the teachings of the Catholic church.

“As an educational institution, Fontbonne retains control over its mission and message. It is not forced to allow Barrett to dilute that message, where he will not be a teacher, minister or spokesman for Fontbonne and has not engaged in public advocacy of same-sex marriage,” Wilkins wrote in a ruling issued Wednesday.

The judge also found that a religious exemption to the state anti-discrimination law applies only if a religious organization limits admission to people of a certain religion. Fontbonne is open to students and employees of all faiths, with the exception of its administration and theology faculty.

It was not immediately clear if Fontbonne plans to appeal the ruling. In a statement, the school said it is considering its options.

Fontbonne’s attorney, John Bagley, did not immediately respond to a phone message and email seeking comment.