The Supreme Court on Monday added a major case to its docket this fall to decide who prevails when a group’s religious beliefs conflict with a city’s attempt to eliminate discrimination.

The justices will take up a legal fight from Philadelphia, where city officials ended a contract to provide foster care services with Catholic Social Services because the agency said it would not accept applications from same-sex couples who want to take care of children. The case will be heard in the term that begins in October.

The U.S. Court of Appeals for the 3rd Circuit ruled the city was within its rights to end the contract and was not targeting the Catholic agency in enforcing its policy that those with whom it does business not discriminate.

Philadelphia’s contract with the agency has expired, but the group is asking the court to require the city to renew it.

The case will be seen as a major test of whether the Supreme Court will reconsider precedents that uphold generally applicable laws that do not specifically target religious groups.

The justices punted on that question in 2018, when they considered the case of a Colorado baker who refused to discuss making a wedding cake for a gay couple, even though a state law prohibited discrimination based on sexual orientation. Similar legal battles are erupting around the country.

Philadelphia and the American Civil Liberties Union previously told the court that the 3rd Circuit’s opinion simply followed the court’s precedents and did not demand review. A flurry of statements from both sides followed the court’s announcement it was taking the case.

Marcel S. Pratt, Philadelphia’s city solicitor, had told the court that it would create “mayhem” if it did not allow the city to follow its own policies in awarding contracts.

In a statement following the grant, Pratt said: “The City of Philadelphia is proud of our long-standing commitment to supporting freedom of religion and preserving equal access to services for all people — regardless of their race, national origin, religion, age, sex, disability, sexual orientation, or gender identity.”

“Unfortunately,” he continued, “CSS refused to consider qualified same-sex couples to become foster parents — even when these couples would be a safe, loving family for the child — and in doing so, CSS defied the city’s nondiscrimination policy.”

Leslie Cooper, deputy director of the ACLU LGBT & HIV Project, said the case could have profound consequences for “more than 400,000 children in foster care across the country. . . . Allowing foster care agencies to exclude qualified families based on religious requirements that have nothing to do with the ability to care for a child, such as their sexual orientation or faith, would make it even worse.”

Lori Windham, senior counsel at the Becket Fund, which represents the agency, said it is Philadelphia that is putting children at risk.

“Over the last few years, agencies have been closing their doors across the country, and all the while children are pouring into the system,” Windham said in a statement. “We are confident that the court will realize that the best solution is the one that has worked in Philadelphia for a century — all hands on deck for foster kids.”

The agency is asking the court to reconsider an important 1990 decision written by Justice Antonin Scalia that limited constitutional protections for religious groups challenging laws that apply to everyone.

That decision, Employment Division v. Smith, said there was no special protection from laws of general applicability. “We have never held that an individual’s religious beliefs excuse him from compliance with an otherwise valid law prohibiting conduct that the state is free to regulate,” Scalia wrote.

But the decision has become unpopular, and the court’s four most conservative members — Justices Clarence Thomas, Samuel A. Alito Jr., Neil M. Gorsuch and Brett M. Kavanaugh — have said they are open to reconsidering it.

In a separate case Monday, Alito said he was also ready to review another Supreme Court precedent involving religious rights.

Joined by Thomas and Gorsuch, Alito said it was time to reconsider Trans World Airlines v. Hardison, a 1977 ruling that limited how far employers must go to accommodate employee’s religious practices.

Alito agreed with the rest of the court not to accept a case from a Seventh-day Adventist who was fired after refusing a Saturday shift in what his employer, Walgreens, said was an emergency. The company generally accommodated Darrell Patterson.

“I agree in the end that this case does not present a good vehicle for revisiting Hardison,” Alito wrote, but he added that the court would be on the lookout for a case that did.