Justice Samuel A. Alito Jr., in his dissent, saw a broader threat from the majority opinion. “It will be used to vilify Americans who are unwilling to assent to the new orthodoxy,” Justice Alito wrote. “In the course of its opinion, the majority compares traditional marriage laws to laws that denied equal treatment for African-Americans and women. The implications of this analogy will be exploited by those who are determined to stamp out every vestige of dissent.”

Gay rights advocates had constructed a careful litigation and public relations strategy to build momentum and bring the issue to the Supreme Court when it appeared ready to rule in their favor. As in earlier civil rights cases, the court had responded cautiously and methodically, laying judicial groundwork for a transformative decision.

It waited for scores of lower courts to strike down bans on same-sex marriages before addressing the issue, and Justice Kennedy took the unusual step of listing those decisions in an appendix to his opinion.

Chief Justice Roberts said that only 11 states and the District of Columbia had embraced the right to same-sex marriage democratically, at voting booths and in legislatures. The rest of the 37 states that allow such unions did so because of court rulings. Gay rights advocates, the chief justice wrote, would have been better off with a victory achieved through the political process, particularly “when the winds of change were freshening at their backs.”

In his own dissent, Justice Scalia took a similar view, saying that the majority’s assertiveness represented a “threat to American democracy.”

But Justice Kennedy rejected that idea. “It is of no moment whether advocates of same-sex marriage now enjoy or lack momentum in the democratic process,” he wrote. “The issue before the court here is the legal question whether the Constitution protects the right of same-sex couples to marry.”

Later in the opinion, Justice Kennedy answered the question. “The Constitution,” he wrote, “grants them that right.”