But the opinion was a narrow one, applying to the specific facts of this case only. It gave no hint as to how the court might decide future cases involving florists, bakers, photographers and other business owners who have cited religious and free-speech objections when refusing to serve gay and lesbian customers in the wake of the Supreme Court's 2015 same-sex marriage decision.
In the 7-2 decision, the court said legal proceedings in Colorado had shown a hostility to the baker's religious views. Monday's ruling was written by Justice Anthony Kennedy, who also wrote the Supreme Court's same-sex marriage decision.
Similar cases are now working their way through the lower courts.
"These disputes must be resolved with tolerance, without undue disrespect to sincere religious beliefs, and without subjecting gay persons to indignities when they seek goods and services in an open market," Kennedy wrote.
But the ruling, which came during Pride Month, gave little guidance to the lower courts about how to balance those competing interests.
Let our news meet your inbox. The news and stories that matters, delivered weekday mornings.
The decision was a victory for Jack Phillips of Masterpiece Cake in Denver, who has said that his cakes are works of art and that requiring him to bake them for same-sex weddings would force him to express a view that violated his religious beliefs. He runs his business guided by religious principles, closing on Sunday and refusing to make cakes containing alcohol or celebrating Halloween.
In 2012, when David Mullins and Charlie Craig walked into his shop and asked him to bake a cake for a reception to celebrate their wedding, Phillips said, "I'm sorry, guys, I can't do that."
What followed, Mullins said, "was this horrible pregnant pause while what was happening sunk in, and we were mortified."
After the couple filed a formal complaint, Colorado courts ruled that the state's public accommodation law, which bans discrimination by companies offering their services to the public, did not allow Phillips to refuse the gay couple's request. A reasonable person would assume that the cake expressed the message of the couple, not the baker, the courts said.
In a statement obtained by the Associated Press, Phillips' Supreme Court lawyer praised Monday's outcome.
“Government hostility toward people of faith has no place in our society, yet the state of Colorado was openly antagonistic toward Jack’s religious beliefs about marriage. The court was right to condemn that,” said Kristen Waggoner, senior counsel with the Alliance Defending Freedom, a conservative Christian nonprofit.
The ACLU, representing Mullins and Craig, said they never discussed with Phillips what kind of design, if any, they wanted on their cake, diminishing his claim that his freedom of expression was at stake.
"He simply turned us away just because of who we are instead of what we asked for," Craig said.
The ACLU said in a statement Monday, "The Supreme Court today reaffirmed the core principle that businesses open to the public must be open to all. ... The court did not accept arguments that would have turned back the clock on equality by making our basic civil rights protections unenforceable, but reversed this case based on concerns specific to the facts here."
Liberal justices Ruth Bader Ginsburg and Sonia Sotomayor dissented Monday, while Stephen Breyer and Elena Kagan joined with the conservatives — Samuel Alito, Neil Gorsuch, Clarence Thomas, and Chief Justice John Roberts — in the outcome.
After Colorado's Civil Rights Commission said that Phillips could not discriminate by refusing to make cakes for same-sex weddings, he chose to stop baking wedding cakes for all customers, which he said cost him about 40 percent of his business.
He had said a Supreme Court ruling in his favor would "declare to the world that my faith is not a scarlet letter."