The U.S. Supreme Court on Thursday unanimously sided with a Catholic foster care agency in Philadelphia that had refused to place children with gay and lesbian couples.

In Fulton v. Philadelphia, the high court agreed with Catholic Social Services' claim that under the First Amendment it can refuse placements with LGBT families for religious reasons.

The ruling was written by Chief Justice John Roberts.

“The refusal of Philadelphia to contract with CSS for the provision of foster care services unless the agency agrees to certify same-sex couples as foster parents cannot survive strict scrutiny and violates the Free Exercise Clause of the First Amendment,” Roberts wrote.

In 2018, the city of Philadelphia learned that Catholic Social Services was refusing to place children with gay couples, a violation of the contract the agency signed with the city. After the city threatened to terminate its contract, CSS sued the city.

Catholic Social Services lost its case in lower courts.

The unanimous decision, however, was specific to the city of Philadelphia's contract with CSS, which is expected to limit its reach.

“SCOTUS issues a narrow ruling in #Fulton in favor of religious foster care agency Catholic Social Services in Philadelphia but does not create a sweeping new religious exemption to nondiscrimination law,” GLBTQ Legal Advocates & Defenders (GLAD), a legal LGBT group, tweeted.

The Human Rights Campaign (HRC), the nation's largest LGBT rights advocate, added: “#SCOTUS has ruled non-discrimination laws apply to taxpayer-funded child services so long as they are enforced neutrally but that Philadelphia's law was not neutral.”

In a press release, the American Civil Liberties Union (ACLU) declared that the high court's decision in Fulton “does not create a license to discriminate based on religious beliefs.”

“We are relieved that the court did not recognize a license to discriminate based on religious beliefs,” said Leslie Cooper, deputy director of the ACLU LGBTQ & HIV Project. “Opponents of LGBTQ equality have been seeking to undo hard-won non-discrimination protections by asking the court to establish a constitutional right to opt out of such laws when discrimination is motivated by religious beliefs. This is the second time in four years that the court has declined to do so. This is good news for LGBTQ people and for everyone who depends on the protections of non-discrimination laws."