Updated at 12:46 p.m. EST

A divided U.S. Supreme Court on Monday ruled for a Colorado baker who refused on religious grounds to make a custom wedding cake for a same-sex couple.

In Masterpiece Cakeshop v. Colorado Civil Rights Commission, the 7-2 majority, led by Justice Anthony Kennedy, said the state commission's order that baker Jack Phillips “cease and desist” discriminating against same-sex couples violated his First Amendment right of free exercise of religion.

Justice Anthony Kennedy

“Whatever the confluence of speech and free exercise principles might be in some cases, the Colorado Civil Rights Commission's consideration of this case was inconsistent with the state's obligation of religious neutrality,” Kennedy wrote. “The reason and motive for the baker's refusal were based on his sincere religious beliefs and convictions.”

Kennedy also made clear the decision was relevant for this case only. “The outcome of cases like this in other circumstances must await further elaboration in the courts, 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,” he wrote.

During oral arguments in the case, Kennedy was visibly angry about the disparaging comments made by a commissioner when the state commission held its hearing on the discrimination charge.

Kennedy, who has authored key Supreme Court decisions favoring gay rights, stated in his opinion, “Our society has come to the recognition that gay persons and gay couples cannot be treated as social outcasts or as inferior in dignity and worth. For that reason the laws and the Constitution can, and in some instances must, protect them in the exercise of their civil rights.”

But he added, “At the same time, the religious and philosophical objections to gay marriage are protected views and in some instances protected forms of expression.”

Justice Ruth Bader Ginsburg dissented, joined by Justice Sonia Sotomayor. Ginsburg said the commission's actions “do not evidence hostility to religion of the kind we have previously held to signal a free-exercise violation, nor do the comments by one or two members of one of the four decisionmaking entities considering this case justify reversing the judgment below.”

In 2012, Charlie Craig and David Mullins visited the Masterpiece bakery and asked its owner, Phillips, to create a cake for their wedding. Phillips declined, saying he did not make cakes for same-sex weddings because of his Christian beliefs and because same-sex marriage was not then legal in Colorado.

Craig and Mullins filed a complaint with the Colorado Civil Rights Commission, alleging discrimination on the basis of their sexual orientation. The state public accommodations law, similar to laws in 22 states, prohibits any place of business engaged in sales to the public from discriminating on the basis of disability, race, creed, color, sex, sexual orientation, marital status, national origin, or ancestry.

The commission and later the Colorado Court of Appeals ruled in favor of the two men. The Colorado Supreme Court denied Masterpiece Cake's request for further review.

In the high court, Phillips, represented by Kristen Waggoner of Alliance Defending Freedom, argued that applying the state anti-discrimination law violated both his speech and religious exercise rights under the First Amendment.

David Cole, national legal director of the American Civil Liberties Union, argued on behalf of Craig and Mullins. Colorado Solicitor General Frederick Yarger argued for the state commission. In a statement, Craig and Mullins said: “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.”

Louise Melling, deputy legal director of the ACLU, said in a statement:

“The court reversed the Masterpiece Cakeshop decision based on concerns unique to the case but reaffirmed its longstanding rule that states can prevent the harms of discrimination in the marketplace, including against LGBT people.”

Phillips drew support from the Trump administration's Justice Department. In a friend-of-the-court brief, the U.S. Solicitor General's Office argued that the justices could decide the case on the speech claim alone.

U.S. Attorney General Jeff Sessions said in a statement:

“We are pleased with today's Supreme Court decision. The First Amendment prohibits governments from discriminating against citizens on the basis of religious beliefs. The Supreme Court rightly concluded that the Colorado Civil Rights Commission failed to show tolerance and respect for Mr. Phillips' religious beliefs. In this case and others, the Department of Justice will continue to vigorously defend the free speech and religious freedom First Amendment rights of all Americans.”

During high court arguments in December, the justices seemed closely divided, with those on the left deeply skeptical of Phillips' speech claim and those on the right more sympathetic to his religion claim.

A number of justices raised concerns about where to draw the line as to which types of speech are protected. Justice Stephen Breyer said at the time, “We want some kind of distinction that won't undermine every civil rights law including African-Americans, Hispanic Americans, including everybody who has been discriminated against in very basic things of life, food, design of furniture, homes and buildings.”

The intense interest in the case was reflected in the overflow crowd outside of the high court on argument day as well as by the outpouring of supporting briefs on each side. Fifty amicus briefs were filed in support of Phillips; 45 amicus briefs supported the same-sex couple.

The Supreme Court's ruling in Masterpiece Cakeshop is posted below:

This report was updated with comment about the Supreme Court's ruling.

Read more: