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.