In a landmark ruling for gay rights, the Supreme Court on Wednesday struck down the Defense of Marriage Act, the 1996 law blocking federal recognition of same-sex marriages.
The decision was 5-4, written by Justice Anthony Kennedy. It said that the law amounted to the "deprivation of the equal liberty of persons that is protected by the Fifth Amendment."
In a separate case, the court ruled that it could not take up a challenge to Proposition 8, the California law that banned gay marriage in that state. That decision means that gay marriage will once again be legal in California.
That decision was also 5-4, written by Chief Justice John Roberts.
The ruling on the Defense of Marriage Act means that the federal government must recognize the gay marriages deemed legal by the states — 12 plus the District of Columbia, before the California case was decided.
The law helps determine who is covered by more than 1,100 federal laws, programs and benefits, including Social Security survivor benefits, immigration rights and family leave.
"DOMA instructs all federal officials, and indeed all persons with whom same-sex couples interact, including their own children, that their marriage is less worthy than the marriages of others," the ruling said. It added that the law was invalid because there was no legitimate purpose for disparaging those whom states "sought to protect in personhood and dignity."
President Barack Obama, in a post on Twitter, said that the ruling was a "historic step forward for #MarriageEquality."
Kennedy was joined in the majority by the four members of the court's liberal wing, Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor and Elena Kagan. Dissenting were Roberts and Justices Antonin Scalia, Clarence Thomas and Samuel Alito.
Scalia, in his dissent, wrote: "We have no power to decide this case. And even if we did, we have no power under the Constitution to invalidate this democratically adopted legislation. The Court's errors on both points spring forth from the same diseased root: an exalted conception of the role of this institution in America."
Cheers went up outside the Supreme Court, where supporters of gay marriage waved signs, rainbow banners and flags with equality symbols.
The ruling comes as states are authorizing gay marriage with increasing speed and with public opinion having turned narrowly in favor of gay marriage.
Under the law, gay couples who are legally married in their states were not considered married in the eyes of the federal government, and were ineligible for the federal benefits that come with marriage.
The case before the Supreme Court, U.S. v. Windsor, concerned Edith Windsor and Thea Spyer, a lesbian couple who lived together in New York for 44 years and married in Canada in 2007.
When Spyer died in 2009, Windsor was hit with $363,000 in federal estate taxes. Had the couple been considered by the federal government to be married, Windsor would not have incurred those taxes.
Kennedy, in the ruling, said that New York's decision to authorize gay marriage was a proper exercise of its authority, and reflected "the community's considered perspective on the historical roots of the institution of marriage and its evolving understanding of the meaning of equality."
President Bill Clinton signed the act into law in September 1996. A court ruling in Hawaii had raised the prospect that that state might become the first to authorize gay marriage.
At the time, some members of Congress believed that the Defense of Marriage Act might be a compromise that would take the air out of a movement to amend the Constitution to block gay marriage.