The Supreme Court ruled Monday in favor of a Colorado baker who refused to make a wedding cake for a same-sex couple, in one of the most closely watched cases of the term.

In a 7-2 decision, the justices set aside a Colorado court ruling against the baker -- while stopping short of deciding the broader issue of whether a business can refuse to serve gay and lesbian people. The opinion was penned by Justice Anthony Kennedy, who is often the swing justice in tight cases.

The narrow ruling here focused on what the court described as anti-religious bias on the Colorado Civil Rights Commission when it ruled against baker Jack Phillips.

"The Commission’s hostility was inconsistent with the First Amendment’s guarantee that our laws be applied in a manner that is neutral toward religion," Kennedy wrote in his majority opinion.

READ THE DECISION

Attorney Michael Farris, president of the Alliance Defending Freedom which represented the baker, told Fox News that Phillips is “ecstatic” at the decision.

“Justice Kennedy has held that tolerance is a two-way street, and Jack Phillips was not tolerated by the Civil Rights Commission of Colorado,” he said.

The court said the broader issue, though, "must await further elaboration."

“The reason and motive for the baker’s refusal were based on his sincere religious beliefs and convictions. The Court’s precedents make clear that the baker, in his capacity as the owner of a business serving the public, might have his right to the free exercise of religion limited by generally applicable laws," Kennedy wrote. "Still, the delicate question of when the free exercise of his religion must yield to an otherwise valid exercise of state power needed to be determined in an adjudication in which religious hostility on the part of the State itself would not be a factor in the balance the State sought to reach."

At issue was a July 2012 encounter. At the time, Charlie Craig and David Mullins of Denver visited Masterpiece Cakeshop to buy a custom-made wedding cake. Phillips refused his services when told it was for a same-sex couple. The state civil rights commission sanctioned Phillips after a formal complaint from the gay couple.

Mullins has described their case as symbolizing “the rights of gay people to receive equal service in business … about basic access to public life."

But the Trump administration backed Phillips, who was represented in court by the Alliance Defending Freedom, a conservative Christian nonprofit. He had lost at every step in the legal appeals process, bringing the case down to the Supreme Court's decision Monday.

"Today’s decision means our fight against discrimination and unfair treatment will continue. We have always believed that in America, you should not be turned away from a business open to the public because of who you are. We brought this case because no one should have to face the shame, embarrassment, and humiliation of being told 'we don’t serve your kind here' that we faced, and we will continue fighting until no one does," Craig and Mullins responded Monday.

Phillips has said he lost business and had to let employees go because of the controversy.

And he has maintained that it’s his choice: "It's not about turning away these customers, it's about doing a cake for an event -- a religious sacred event -- that conflicts with my conscience," he said last year.

The court in December specifically examined whether applying Colorado's public accommodations law to compel the local baker to create commercial "expression" violated his constitutionally protected Christian beliefs about marriage.

By wading again into the culture wars, the justices had to confront recent decisions on both gay rights and religious liberty: a 2015 landmark opinion legalizing same-sex marriage nationwide and a separate 2014 decision affirming the right of some companies to act on their owner's faith by refusing to provide contraception to its workers.

The Trump administration agreed with Phillips' legal claims to a large extent. Attorney General Jeff Sessions in October issued broad guidance to executive branch agencies, reiterating the government should respect religious freedom, which in the Justice Department's eyes extends to people, businesses and organizations.

But civil rights groups were concerned the conservative majority on the court may be ready to peel back protections for groups with a history of enduring discrimination – and predicted that giving businesses the right to refuse service to certain customers would undermine non-discrimination laws and hurt minorities.

When the justices heard arguments in December, Kennedy was plainly bothered by certain comments by a commission member. The commissioner seemed "neither tolerant nor respectful of Mr. Phillips' religious beliefs," Kennedy said in December.

Liberal justices Stephen Breyer and Elena Kagan joined the conservative justices in the outcome. Kagan wrote separately to emphasize the limited ruling.

But Justices Ruth Bader Ginsburg and Sonia Sotomayor dissented.

"I see no reason why the comments of one or two Commissioners should be taken to overcome Phillips’ refusal to sell a wedding cake to Craig and Mullins," Ginsburg wrote.

Sarah Warbelow, legal director with the Human Rights Campaign, also stressed that the decision “is so narrow as to apply only to this particular baker.”

Fox News' Mike Emanuel and The Associated Press contributed to this report.