WASHINGTON — His vote likely to decide the outcome, Supreme Court Justice Anthony Kennedy voiced competing concerns Tuesday about respecting the religious beliefs of a Colorado baker who wouldn’t make a wedding cake for a same-sex couple, and the gay couple’s dignity.

Kennedy, the author of all the court’s major gay-rights decisions, worried early in a riveting argument at the high court that a ruling in favor of baker Jack Phillips might allow shop owners to put up signs saying, “We do not bake cakes for gay weddings.”

But later, Kennedy said the Colorado Civil Rights Commission seemed “neither tolerant nor respectful of Mr. Phillips’ religious beliefs” when it found his refusal to bake a cake for the gay couple violated the state’s anti-discrimination law.

Phillips and the couple, Charlie Craig and David Mullins, were all in the courtroom Tuesday to listen to an argument that otherwise seemed to put the conservative justices squarely with Phillips and the liberals on the couple’s side.

The case pits Phillips’ First Amendment claims of artistic freedom against the anti-discrimination arguments of the Colorado commission, and the two men Phillips turned away in 2012.

The argument was the first involving gay rights since the Supreme Court ruled in 2015 that states could not prevent same-sex couples from marrying.

The Trump administration is supporting Phillips in his argument that he can’t be forced to create a cake that violates his religious beliefs. It appears to be the first time the federal government has asked the justices to carve out an exception from an anti-discrimination law.

Protesters on both sides filled the sidewalk in front of the court, shortly before the start of the argument.

Inside the packed courtroom, the liberal justices peppered Phillips’ lawyer, Kristen Waggoner, and Solicitor General Noel Francisco with questions about how to draw a line to accommodate Phillips without eviscerating laws that require businesses that are open to the public to serve all customers.

The case’s outcome could affect photographers and florists who have voiced objections similar to those of Phillips.

Justices Ruth Bader Ginsburg and Elena Kagan ticked off other categories of people who are involved in weddings to ask if they too might be able to refuse a same-sex couple. A graphic artist who designs menus and invitations? A jeweler? A hairstylist? A makeup artist?

Waggoner said the person who makes menus and invitations might be in the same position as Phillips, but not the others because what they do is “not speech.”

Kagan replied: “Some people might say that about cakes, you know?”

More generally, Justice Stephen Breyer, in an exchange with Francisco, said his concern is the court would have “no way of confining” a decision in favor of Phillips.

Kennedy’s comments in the first half of the 75-minute argument seemed firmly in line with the concerns for human dignity that Kennedy expressed in his opinion in the 2015 gay marriage case and other gay-rights decisions he has written over more than 20 years. Kennedy expressed his doubts when Francisco tried to describe a narrow range of situations in which Phillips and similarly situated business owners might have a right to refuse service.

“The problem for you is so many examples do involve speech. It basically means there is an ability to boycott,” Kennedy said.

Charlie Craig (left) and David Mullins after leaving the Supreme CourtAP

When Frederick Yarger, the Colorado solicitor general, and the American Civil Liberties Union’s David Cole stood up to defend the commission’s ruling against Phillips, the conservative justices pounced.

Because same-sex marriage was not yet legal in Colorado in 2012, Justice Samuel Alito noted that Craig and Mullins could not have obtained a marriage license where they lived or gotten a local official to marry them. Yet Phillips supposedly “committed a grave wrong” when he refused to make them a cake, Alito said. That struck him as unfair, he said.

Chief Justice John Roberts pressed both Cole and Yarger on whether a Catholic legal services agency that provides help for free would have to take up a case involving a same-sex couple, despite the religious opposition to same-sex marriage. Yes, Cole said, “if they’ve provided the same services to couples who are straight.”

Colorado native Neil Gorsuch, taking part in the most important gay rights case since he joined the Supreme Court in April, asked Cole whether a baker who made a cake shaped like a red cross to celebrate relief efforts also would have to make the same cake for the Ku Klux Klan.

Cole said no, because Colorado’s anti-discrimination law refers to race, sex and sexual orientation, but does not protect KKK members.

Kennedy’s questions in this portion of the argument seemed to reflect his strong First Amendment views in favor of free speech and religion that he has developed in nearly 30 years on the court.

Kennedy described comments made by one of the seven Colorado commissioners in the case as hostile to religion. “Did the commission ever disavow or disapprove” of those remarks, he asked.

Not before today, Yarger said, disavowing them.

The exchange raised another possibility: that the court could return the case to the commission for reconsideration because its first decision was tainted by religious bias.

Colorado is among only 21 states with statewide laws barring discrimination against gays and lesbians in public accommodations.

The case, Masterpiece Cakeshop v. Colorado Civil Rights Commission, 16-111, will be decided by late June.