WASHINGTON (AP) — The Supreme Court declared Friday that same-sex couples have a right to marry anywhere in the United States, a historic culmination of decades of litigation over gay marriage and gay rights generally.
Gay and lesbian couples already could marry in 36 states and the District of Columbia. The court’s 5-4 ruling means the remaining 14 states, in the South and Midwest, will have to stop enforcing their bans on same-sex marriage.
A court in Atlanta issued marriage licenses to three same-sex couples Friday morning, soon after the decision.
Gay rights supporters cheered, danced and wept outside the court after the decision, which put an exclamation point on breathtaking changes in the nation’s social norms.
Justice Anthony Kennedy wrote the majority opinion, just as he did in the court’s previous three major gay rights cases dating back to 1996. It came on the anniversary of two of those earlier decisions.
‘‘No union is more profound than marriage,’’ Kennedy wrote, joined by the court’s four more liberal justices.
The stories of the people asking for the right to marry ‘‘reveal that they seek not to denigrate marriage but rather to live their lives, or honor their spouses’ memory, joined by its bond,’’ Kennedy said.
As he read his opinion, spectators in the courtroom wiped away tears after the import of the decision became clear. One of those in the audience was James Obergefell, the lead plaintiff in the Supreme Court fight.
Outside, Obergefell held up a photo of his late spouse, John, and said the ruling establishes that ‘‘our love is equal.’’ He added, ‘‘This is for you, John.’’
President Barack Obama placed a congratulatory phone call to Obergefell, which he took amid a throng of reporters outside the courthouse.
Speaking a few minutes later at the White House, Obama praised the decision as ‘‘justice that arrives like a thunderbolt.’’ He said it was an affirmation of the principle that ‘‘all Americans are created equal.’’
The four dissenting justices each filed a separate opinion explaining his views, but they all agreed that states and their voters should have been left with the power to decide who can marry.
‘‘This court is not a legislature. Whether same-sex marriage is a good idea should be of no concern to us,’’ Chief Justice John Roberts wrote in dissent. Roberts read a summary of his dissent from the bench, the first time he has done so in nearly 10 years as chief justice.
‘‘If you are among the many Americans — of whatever sexual orientation — who favor expanding same-sex marriage, by all means celebrate today’s decision,’’ Roberts said. ‘‘But do not celebrate the Constitution. It had nothing to do with it.’’
Justice Antonin Scalia said he was not concerned so much about same-sex marriage but about ‘‘this court’s threat to American democracy.’’ Justices Samuel Alito and Clarence Thomas also dissented.
Several religious organizations criticized the decision and a group of pastors in Texas vowed to defy it.
Kennedy said nothing in the court’s ruling would force religions to condone, much less perform, weddings to which they object.
The ruling will not take effect immediately because the court gives the losing side roughly three weeks to ask for reconsideration. But some state officials and county clerks might follow the lead of the Fulton County, Georgia, probate court and decide there is little risk in issuing marriage licenses to same-sex couples.
The cases before the court involved laws from Kentucky, Michigan, Ohio and Tennessee that define marriage as the union of a man and a woman. Those states have not allowed same-sex couples to marry within their borders and they also have refused to recognize valid marriages from elsewhere.
Just two years ago, the Supreme Court struck down part of the federal anti-gay marriage law that denied a range of government benefits to legally married same-sex couples.
Justices Stephen Breyer, Ruth Bader Ginsburg, Elena Kagan and Sonia Sotomayor formed the majority with Kennedy on Friday, the same lineup as two years ago.
The earlier decision in United States v. Windsor did not address the validity of state marriage bans, but courts across the country, with few exceptions, said its logic compelled them to invalidate state laws that prohibited gay and lesbian couples from marrying.
The number of states allowing same-sex marriage has grown rapidly. As recently as last October, just over one-third of the states permitted it.
There are an estimated 390,000 married same-sex couples in the United States, according to UCLA’s Williams Institute, which tracks the demographics of gay and lesbian Americans. Another 70,000 couples living in states that do not currently permit them to wed would get married in the next three years, the institute says. Roughly 1 million same-sex couples, married and unmarried, live together in the United States, the institute says.
The Obama administration backed the right of same-sex couples to marry. The Justice Department’s decision to stop defending the federal anti-marriage law in 2011 was an important moment for gay rights, and Obama declared his support for same-sex marriage in 2012.
The states affected by Friday’s ruling are: Alabama, Arkansas, Georgia, Kentucky, Louisiana, Michigan, Mississippi, most of Missouri, Nebraska, North Dakota, Ohio, South Dakota, Tennessee and Texas.
Jesse Nunes of Globe Staff contributed to this report. Associated Press writers Jessica Gresko, Sam Hananel and Glynn Hill contributed to this report.