A federal judge on Friday ruled against a religious organization that refused to place foster children with gay families on religious grounds.

Judge Petrese B. Tucker of the U.S. District Court for the Eastern District of Pennsylvania ruled that the city of Philadelphia can require the foster and adoption agencies with which it contracts to abide by the city’s nondiscrimination policies. The decision marks the first time a federal court has ruled that such agencies may not turn away same-sex couples who don’t meet the agencies’ religious criteria.

The plaintiffs in the case — Catholic Social Services and three foster families with whom the agency works — were quick to file an appeal.

The dispute began in early March when the commissioner of Philadelphia’s Department of Human Services (DHS) discovered that two of the 30 foster care agencies with which it has contracts — Catholic Social Services and Bethany Christian Services — had policies that deny their publicly funded services to same-sex couples.

Following this discovery, DHS stopped working with the two organizations, noting that their policies regarding LGBTQ families violated the nondiscrimination clause included in the contract they entered into with DHS.

Catholic Social Services and three foster families then filed a lawsuit against the city of Philadelphia, claiming, among other things, that the city’s suspension of referrals of new children to their care violated their religious and free speech rights.

Friday’s ruling found that Catholic Social Services’ practices violated the Philadelphia Fair Practices Ordinance, which prohibits discrimination on the basis of sexual orientation and gender identity, and therefore the agency was not entitled to continue to receive public funding. According to court documents, Catholic Social Services currently has a $19.4 million contract with Philadelphia’s Department of Human Services.

Judge Tucker found that DHS and the city of Philadelphia have a “legitimate interest” in ensuring that public services are “accessible to all Philadelphians who are qualified for the services,” and that “the pool of foster parents and resource caregivers is as diverse and broad as the children in need.”

Judge Tucker further noted that DHS and the city have a legitimate interest in “avoiding likely Equal Protection Clause and Establishment Clause claims that would result if it allowed its government contractors to avoid compliance” with the city’s nondiscrimination provisions “by discriminating against same-sex married couples.”

Friday’s ruling came just one day after House Republicans advanced an amendment that would allow adoption agencies that receive public funding, like Catholic Social Services, to refuse to work with same-sex couples on religious grounds.

The amendment would permit the Department of Health and Human Services to withhold “15 percent of the federal funds the state or local government receives for a program that provides child welfare services” from any state or local government that was found to “discriminate” against one of these religious agencies.

“HARMFUL POLICY” OR “VICTORY FOR CHILDREN”?

The Becket Fund for Religious Liberty is representing Catholic Social Services and its foster families in court. The organization’s senior counsel, Lori Windham, slammed Philadelphia’s policy and promised to fight Judge Tucker’s decision.

“Foster children deserve loving homes,” Windham said in a statement. “But the trial court allowed the City to continue its harmful policy — a decision we expect to change with this appeal.”

The Becket Fund has developed a track record of successfully litigating religious liberty cases, including the 2014 Hobby Lobby case at the Supreme Court. In a landmark decision for religious liberty advocates, the high court sided with Hobby Lobby and ruled the government could not compel the arts and crafts store to provide contraception for female employees when to do so would violate the religious beliefs of the store’s owners.

Civil rights and child welfare advocates applauded Judge Tucker’s ruling.

“First and foremost, this is a victory for children in Philadelphia who need a loving home and can’t afford to have good families turned away for failing to meet a religious litmus test,” Reggie Shuford, executive director of the American Civil Liberties Union of Pennsylvania said in a statement. “We’re proud that the city is committed to ensuring that no qualified family that comes forward to care for a child in need is turned away because of their sexual orientation or other reasons unrelated to the ability to care for a child.”

Christina Remlin, lead counsel at Children’s Rights, a nonprofit child welfare organization, said exclusionary policies, like the one Catholic Social Services had in place, could have a trickle-down effect.

“When you have a provider agency that espouses intolerant views and promulgates them and stands by them, that kind of culture tends to permeate down to the foster parent and adoptive parent level, so that around the kitchen table at breakfast, you have a situation in which foster parents are espousing the belief that, for example, being gay means that you should be sent to hell,” Remlin said following the ruling.

IMPACT BEYOND PHILADELPHIA

Leslie Cooper, deputy director of the ACLU’s LGBT and HIV Project, called the ruling “historic.” and said it could have an impact far beyond Philadelphia. Judge Tucker’s decision, she argued, could have “persuasive authority” in other cases, such as Dumont v. Lyon in Michigan, where the roles are reversed — the government is defending the ability of faith-based foster and adoption agencies to turn away same-sex couples.

Ten states in the U.S. currently permit state-licensed child welfare agencies to refuse to place children with same-sex couples if doing so conflicts with their religious beliefs, according to the Movement Advancement Project, an LGBTQ think tank. Cooper said Judge Tucker’s ruling implies these states are vulnerable to lawsuits on the basis of the Establishment Clause of the Constitution.

FOLLOW NBC OUTON TWITTER, FACEBOOK AND INSTAGRAM