The foster care agency relied on the decision, Masterpiece Cakeshop v. Colorado Civil Rights Commission, in arguing that it too had been subjected to hostility based on anti-religious prejudice. It added that its free-speech rights would be violated were it forced to certify that same-sex couples are fit to be foster parents.

The city responded that the agency was not entitled to rewrite government contracts to eliminate anti-discrimination clauses.

“It has never been the case that religious entities, or entities with deeply held secular views, are constitutionally entitled to enter into government contracts and then defy any terms to which they object,” the city’s brief said. If the agency’s “sweeping constitutional claims were accepted,” the brief said, “they would cause mayhem in government contracting.”

The agency asked the court to use the case to reconsider an important precedent limiting First Amendment protections for religious practices. The precedent, Employment Division v. Smith in 1990, ruled that neutral laws of general applicability could not be challenged on the ground that they violated the First Amendment’s protection of the free exercise of religion.

The decision, arising from a case involving the use of peyote in Native American religious ceremonies, is unpopular among conservative Christians, who say it does not offer adequate protection to religion, and with some justices. Last year, the court’s four most conservative members — Justices Kavanaugh, Clarence Thomas, Samuel A. Alito Jr. and Neil M. Gorsuch — signaled that they were open to reconsidering the decision.

The court is likely to hear arguments in the case in the fall, after its next term starts in October.

In a second case concerning religion, the court turned down a request that it decide whether Walgreens was entitled to fire a worker who refused to attend a training session on his Sabbath.