The Supreme Court, in a majority decision, ruled that a Catholic foster care agency could resist city rules and refuse to work with same-sex couples who apply to take in foster children.

The group, Catholic Social Services, claimed that Philadelphia's attempts to "exclude the Catholic Church from foster care" violated the U.S. First Amendment.

The ruling was a major setback for gay rights and further evidence that religious organizations almost always win in the current U.S. justice system, according to The New York Times.

CSS said its religious views prevent it from screening same-sex couples as foster parents. The agency has a long history of foster care and said it shouldn't be restrained from its advocacies because of its religious beliefs.

"The refusal of Philadelphia to contract with CSS for foster care services, unless it agrees to certify same-sex couples as foster parents, cannot survive strict scrutiny and violates the First Amendment," USA Today quoted Chief Justice John Roberts as saying.

Roberts said that "it is plain that Philadelphia's actions have burdened CSS's religious exercise by putting it to the choice of curtailing its mission or approving relationships inconsistent with its beliefs."

Roberts was joined in his opinion by justices Sonia Sotomayor, Stephen Breyer, Brett Kavanaugh, Elena Kagan and Amy Coney Barrett.

The opinion drew criticism from the court's conservatives. Associate Justice Neil Gorsuch accused his colleagues of seeking to "sidestep the question."

City Solicitor Diana Cortes, for her part, warned of "disturbing consequences" for other government programs and services.

The court proceeding started in 2018, when the city learned from a Philadelphia Inquirer report that two of the 30 agencies it contracted with to provide foster care services had policies against approving married same-sex couples as foster parents.

Many legal experts had predicted the court would rule in favor of CSS.