In deciding its first cases on the issue, the high court did not issue the sweeping declaration sought by gay rights advocates that would have allowed same-sex couples to marry anywhere in the country. But in two rulings, both by bare 5-4 majorities, the justices gave gay marriage supporters encouragement in confronting the nationwide patchwork of laws that outlaw such unions in roughly three dozen states.
Gay-rights supporters cheered and hugged outside the court. Opponents said they mourned the rulings and vowed to keep up their fight.
In the first of the narrow rulings in its final session of the term, the court wiped away part of a federal anti-gay marriage law, the Defense of Marriage Act, that has kept legally married same-sex couples from receiving tax, health and pension benefits that are otherwise available to married couples.
Justice Anthony Kennedy, joined by the four liberal justices, said the purpose of the law was to impose a disadvantage and "a stigma upon all who enter into same-sex marriages made lawful by the unquestioned authority of the states."
President Barack Obama praised the court's ruling against the federal marriage act, labeling the law "discrimination enshrined in law."
"It treated loving, committed gay and lesbian couples as a separate and lesser class of people," Obama said in a statement. "The Supreme Court has righted that wrong, and our country is better off for it."
House Speaker John Boehner, R-Ohio, said he was disappointed in the outcome of the federal marriage case and hoped states continue to define marriage as the union of a man and a woman. Boehner, as speaker, had stepped in as the main defender of the law before the court after the Obama administration declined to defend it.
The other case, dealing with California's constitutional ban on same-sex marriage, was resolved by an unusual lineup of justices in a technical legal fashion that said nothing about gay marriage. But the effect was to leave in place a trial court's declaration that California's Proposition 8 ban was unconstitutional. Gov. Jerry Brown quickly ordered that marriage licenses be issued to gay couples as soon as a federal appeals court lifts its hold on the lower court ruling. That will take least 25 days, the appeals court said.
California, where gay marriage was briefly legal in 2008, would be the 13th state, along with the District of Columbia, to allow same-sex couples to marry and would raise the share of the U.S. population in gay marriage states to 30 percent. Six states have adopted same-sex marriage in the past year, amid a rapid evolution in public opinion that now shows majority support for the right to marry in most polls.
The 12 other states are Connecticut, Delaware, Iowa, Maine, Maryland, Massachusetts, Minnesota, New Hampshire, New York, Rhode Island, Vermont and Washington.
The day's rulings are clear for people who were married and live in states that allow same-sex marriage. They now are eligible for federal benefits.
The picture is more complicated for same-sex couples who traveled to another state to get married, or who have moved from a gay marriage state since being wed.
Their eligibility depends on the benefits they are seeking. For instance, immigration law focuses on where people were married, not where they live. But eligibility for Social Security survivor benefits basically depend on where a couple is living when a spouse dies.
This confusing array of regulations is reflected more broadly in the disparate treatment of gay couples between states. And the court's decision did not touch on another part of the federal marriage law that says a state does not have to recognize a same-sex marriage performed elsewhere.
Indeed, the outcome of the cases had supporters of gay marriage already anticipating their next trip to the high court, which they reason will be needed to legalize same-sex unions in all 50 states.
The Human Rights Campaign's president, Chad Griffin, said his goal is to legalize same-sex marriage nationwide within five years through a combination of ballot measures, court challenges and expansion of anti-discrimination laws.
The rulings came 10 years to the day after the court's Lawrence v. Texas decision that struck down state bans on gay sex. In his dissent at the time, Justice Antonin Scalia predicted the ruling would lead to same-sex marriage.
On Wednesday, Scalia issued another pungent dissent in the Defense of Marriage Act case in which he made a new prediction that the ruling would be used to upend state restrictions on marriage. Kennedy's majority opinion insisted the decision was limited to legally married same-sex couples.
Scalia read aloud in a packed courtroom that included the two couples who sued for the right to marry in California. On the bench, Justice Elena Kagan, who voted to strike down DOMA, watched Scalia impassively as he read.
"It takes real cheek for today's majority to assure us, as it is going out the door, that a constitutional requirement to give formal recognition to same-sex marriage is not at issue here_when what has preceded that assurance is a lecture on how superior the majority's moral judgment in favor of same-sex marriage is to the Congress' hateful moral judgment against it. I promise you this: The only thing that will 'confine' the court's holding is its sense of what it can get away with," Scalia said.
Scalia and Justice Samuel Alito, who also wrote a dissenting opinion, said their view is that Constitution does not require states to allow gay and lesbian couples to marry.
Outside the court, some in the crowd hugged and others jumped up and down just after 10 a.m. EDT when the DOMA decision was announced. Many people were on their cellphones monitoring Twitter, news sites and blogs for word of the decision. And there were cheers as runners came down the steps with the decision in hand and turned them over to reporters who quickly flipped through the decisions.
Chants of "Thank you" and "U-S-A" came from the crowd as plaintiffs in the cases descended the court's marbled steps. Most of those in the crowd appeared to support gay marriage, although there was at least one man who held a sign promoting marriage as between a man and a woman.
In New York City's Greenwich Village, the Stonewall Inn, where a riot in 1969 sparked the gay rights movement, erupted in cheers and whooping.
Mary Jo Kennedy, 58 was there with her wife Jo-Ann Shain, 60, and their daughter Aliya Shain, 25.
She came with a sign that could be flipped either way and was holding up the side that says "SCOTUS made our family legal".
They have been together 31 years and got married the day it became legal in New York.
Others were not celebrating.
"We mourn for America's future, but we are not without hope," said Tim Wildmon, president of American Family Association, in a statement.
Said. Tony Perkins, president of the Family Research Council: "Time is not on the side of those seeking to create same-sex 'marriage.' As the American people are given time to experience the actual consequences of redefining marriage, the public debate and opposition to the redefinition of natural marriage will undoubtedly intensify."
The federal marriage law had been struck down by several federal courts, and the justices chose to take up the case of 84-year-old Edith Windsor of New York, who sued to challenge a $363,000 federal estate tax bill after her partner of 44 years died in 2009.
Windsor, who goes by Edie, married Thea Spyer in 2007 after doctors told them Spyer would not live much longer. Spyer had suffered from multiple sclerosis for many years. She left everything she had to Windsor.
Windsor arrived at a news conference in New York after the ruling to applause from her supporters and said she felt "joyous, just joyous."
Windsor would have paid nothing in inheritance taxes if she had been married to a man. Now she is eligible for a refund.
In the case involving the federal Defense of Marriage Act, Justice Kennedy was joined by the court's four liberal justices. In the California ruling, which was not along ideological lines, Chief Justice John Roberts' opinion was joined by Scalia and three of those liberal court members: Kagan, Ruth Bader Ginsburg and Stephen Breyer.
Associated Press writers Connie Cass, David Crary, Jessica Gresko, Bethan McKernan and Larry Neumeister contributed to this report. Crary, McKernan and Neumeister reported from New York.