But the comparisons are not completely airtight, said Michael J. Klarman, a legal historian at Harvard Law School.

The decision on interracial marriage in Loving v. Virginia, he said, followed democratic consensus. State legislatures, not judges, had done almost all of the work in driving down the number of bans to 16.

The stunning recent run of victories for same-sex marriage, by contrast, has mostly been the work of judges rather than voters or their elected representatives. In the past two months, the number of states allowing same-sex marriage grew to 35 from 19, as well as the District of Columbia. The surge was entirely the result of court decisions.

The decision in Lawrence v. Texas that struck down antisodomy laws presents a more complicated picture. The decision overruled a 1986 decision, Bowers v. Hardwick. In the intervening years, the number of states with such laws dropped to 13 from 24. Three of the laws were repealed; the rest were struck down by courts.

But Judge Jeffrey S. Sutton, who wrote the majority opinion this month in a decision upholding bans on same-sex marriage in four states — Kentucky, Michigan, Ohio and Tennessee — said the Lawrence decision offered a poor comparison.

“Freed of federal court intervention, 31 states would continue to define marriage the old-fashioned way,” said Judge Sutton, of the United States Court of Appeals for the Sixth Circuit. “Lawrence, by contrast, dealt with a situation in which just 13 states continued to prohibit sodomy, and even then most of those laws had fallen into desuetude, rarely being enforced at all.”

“What right do we have,” he asked, “to say that societal values, as opposed to judicial values, have evolved toward agreement in favor of same-sex marriage?”