The Defense of Marriage Act defines marriage as only between a man and a woman.
The vote Wednesday was 5-4.
"Although Congress has great authority to design laws to fit its own conception of sound national policy, it cannot deny the liberty protected by the Due Process Clause of the Fifth Amendment," said Justice Anthony Kennedy. He was supported by four more liberal colleagues: Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor, and Elena Kagan.
The case examined whether the federal government can deny tax, health and pension benefits to same-sex couples in states where they can legally marry. At issue was whether DOMA violates equal protection guarantees in the Fifth Amendment's due process clause as applied to same-sex couples legally married under the laws of their states.
The key plaintiff is Edith "Edie" Windsor, 84, who married fellow New York resident Thea Spyer in Canada in 2007, about 40 years into their relationship. By the time Spyer died in 2009, New York courts recognized same-sex marriages performed in other countries. But the federal government didn't recognize Windsor's same-sex marriage, and she was forced to assume an estate tax bill much larger than those that other married couples would have to pay. So, Windsor sued the federal government.
A federal appeals court last year ruled in Windsor's favor, saying DOMA violated the Constitution's equal protection clause.
"Today's DOMA ruling is a historic step forward for #MarriageEquality. #LoveIsLove," President Barack Obama's official Twitter account posted soon after the decision was handed down.
Kennedy in his opinion used sweeping language to affirm the rights of gays and lesbians.
"For same-sex couples who wished to be married, the state (of New York) acted to give their lawful conduct a lawful status. This status is a far-reaching legal acknowledgment of the intimate relationship between two people, a relationship deemed by the state worthy of dignity in the community equal with all other marriages," he said. "DOMA seeks to injure the very class New York seeks to protect."
But Kennedy -- a moderate-conservative who proved once again to be the "swing," or deciding, vote -- made clear the ruling is limited: "This opinion and its holding are confined to those lawful marriages." Thirty-five states have laws banning same-sex marriage.
Under DOMA, Social Security, pension and bankruptcy benefits, along with family medical leave protections and other federal provisions, did not apply to gay and lesbian couples legally married in states that recognize such unions.
In a thunderous dissent, read from the bench, Justice Antonin Scalia slammed the majority for its "exalted conception of the role of this institution" -- the Supreme Court -- "in America."
"Few public controversies touch an institution so central to the lives of so many, and few inspire such attendant passion by good people on both sides," he said. "Few public controversies will ever demonstrate so vividly the beauty of what our (Constitution) framers gave us, a gift the court pawns today to buy its stolen moment in the spotlight: a system of government that permits us to rule ourselves."
Scalia added, "Some will rejoice in today's decision, and some will despair at it; that is the nature of a controversy that matters so much to so many. But the court has cheated both sides, robbing the winners of an honest victory, and the losers of the peace that comes from a fair defeat. We owed both of them better. I dissent."
Chief Justice John Roberts and Justices Clarence Thomas and Samuel Alito also dissented.
Windsor was in New York when the ruling came down. She had attended oral arguments in March and said at the time, "I am today an out lesbian, OK, who just sued the United States of America, which is kind of overwhelming for me."
Marriage, she said, is "a magic word, for anyone who doesn't understand why we want it and why we need it."
The Defense of Marriage law was defended in the high court by House Republicans, after Obama concluded the law was unconstitutional.
Traditionally that role would fall to the solicitor general's office. But president ordered Attorney General Eric Holder not to defend DOMA in court. That raised the question of whether any party could rightfully step in and defend the law.
By striking down the DOMA provision, the court decided the standing question was not at play in this case, and it had jurisdiction to decide the larger questions.
A bill known as the Respect for Marriage Act is working its way through Congress and would repeal DOMA.
That law does not prohibit states from allowing same-sex marriages, but it also does not force states to recognize such marriages performed in other states. Most of the current plaintiffs are federal workers, who are not allowed to add their spouses to health care plans and other benefits.
The case is U.S. v. Windsor (12-307).