BOSTON (AP) — Massachusetts' child welfare agency acted within its rights when it denied a couple's application to become foster parents because they spanked their children, the state's highest court ruled Monday.

Gregory and Melanie Magazu, of Fitchburg, said when they applied to become foster parents in 2012 that they used corporal punishment on their biological children in accordance with their Christian faith, but promised not to spank any foster children.

They also said they only spanked their biological children sparingly and in the privacy of their bedroom so as not to humiliate them.

The state Department of Children and Families denied their application in 2013. The agency said that many foster children are traumatized, and seeing another child spanked could further traumatize them.

The Magazus said the department's decision was "arbitrary and capricious," and "infringes on their constitutional right to the free exercise of religion."

They appealed to Superior Court, which affirmed the agency's decision.

The case then went to the Supreme Judicial Court, which upheld the lower court's decision.

"We ... conclude that although the department's decision imposes a substantial burden on the Magazus' sincerely held religious beliefs, this burden is outweighed by the department's compelling interest in protecting the physical and emotional well-being of foster children," the court wrote in its unanimous opinion.

In a brief statement, the agency said it was pleased with the court's ruling but did not elaborate.

The Magazus' lawyer, David Bodanza, did not respond to a phone message.