WASHINGTON — The Supreme Court on Monday ruled in favor of a Colorado baker who had refused to create a wedding cake for a gay couple. The court’s decision was narrow, and it left open the larger question of whether a business can discriminate against gay men and lesbians based on rights protected by the First Amendment.

The court passed on an opportunity to either bolster the right to same-sex marriage or explain how far the government can go in regulating businesses run on religious principles. Instead, Justice Anthony M. Kennedy’s majority opinion turned on the argument that the Colorado Civil Rights Commission, which originally ruled against the baker, had been shown to be hostile to religion because of the remarks of one of its members.

At the same time, Justice Kennedy strongly reaffirmed protections for gay rights.

“The outcome of cases like this in other circumstances must await further elaboration in the courts,” he wrote, “all in the context of recognizing that 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.”

Justice Kennedy often casts the deciding vote in closely divided cases on major social issues. When the court agreed to hear the Colorado case last June, it seemed to present him with a stark choice between two of his core commitments. On the one hand, Justice Kennedy has written every major Supreme Court decision protecting gay men and lesbians. On the other, he is the court’s most ardent defender of free speech.