A divided U.S. Supreme Court overturned the federal law that defines marriage as a heterosexual union, saying it violates the rights of married gay couples by denying them government benefits.

The vote on the Defense of Marriage Act was 5-4. Justice Anthony Kennedy joined the four Democratic-appointed justices in the majority.

“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,” Kennedy wrote for the court.

The court will act momentarily on a second gay-marriage case, involving California’s Proposition 8, which bars same-sex couples from marrying.

The historic cases, which marked the first time the high court had ever considered gay-marriage rights, reached the justices as the movement was showing unprecedented momentum. Twelve states and the District of Columbia have legalized same- sex marriage, six of them in the last year.