The Defense of Marriage Act, the law barring the federal government from recognizing same-sex marriages legalized by the states, is unconstitutional, the Supreme Court ruled Wednesday by a 5-4 vote.

“The federal statute is invalid, for no legitimate purpose overcomes the purpose and effect to disparage and to injure those whom the State, by its marriage laws, sought to protect in personhood and dignity,” Justice Anthony Kennedy wrote in the majority opinion. “By seeking to displace this protection and treating those persons as living in marriages less respected than others, the federal statute is in violation of the Fifth Amendment.”

Justice Kennedy delivered the court’s opinion, and was joined by Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor and Elena Kagan. Chief Justice John Roberts and Justices Antonin Scalia and Samuel Alito all filed dissenting opinions.

DOMA, signed by President Bill Clinton in 1996, prevents same-sex couples whose marriages are recognized by their home state from receiving the hundreds of benefits available to other married couples under federal law. During the Obama administration, the Justice Department initially defended DOMA in court despite the administration’s desire to repeal it. But the Justice Department changed course in early 2011, finding that the law was unconstitutional and declining to defend it any longer. House Republicans have since spent hundreds of thousands of dollars taking over that defense.

Plaintiff Edie Windsor, 84, sued the federal government after the Internal Revenue Service denied her refund request for the $363,000 in federal estate taxes she paid after her spouse, Thea Spyer, died in 2009.