A couple celebrated at City Hall in San Francisco on Wednesday after hearing that the Supreme Court has struck down the Defense of Marriage Act.

WASHINGTON — The Supreme Court issued a pair of rulings Wednesday expanding gay rights, ruling unconstitutional a 1996 law denying federal benefits to legally married same-sex couples and clearing the way for California to legalize same-sex marriage.

In the California case, the court ruled that opponents of same-sex marriage did not have standing to appeal a lower-court ruling that overturned California’s ban. The Supreme Court’s ruling appears to remove legal obstacles to same-sex couples marrying in the state, but the court did not issue a broad ruling likely to affect other states.

The decision on the federal law was 5 to 4, with Justice Anthony M. Kennedy writing the majority opinion, which the four liberal-leaning justices joined.

“The federal statute is invalid, for no legitimate purpose overcomes the purpose and effect to disparage and injure those whom the State, by its marriage laws, sought to protect in personhood and dignity,” Justice Kennedy wrote. “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.”

Chief Justice John G. Roberts was in the minority, as were Justices Antonin Scalia, Clarence Thomas and Samuel Alito.

The ruling overturned the Defense of Marriage Act, which passed with bipartisan support and President Bill Clinton signed.

The decision will immediately extend some federal benefits to same-sex couples, but it will also raise a series of major decisions for the Obama administration about how aggressively to overhaul references to marriage throughout the many volumes that lay out the laws of the United States.

“In the majority’s telling, this story is black-and-white: Hate your neighbor or come along with us,” Justice Scalia wrote in his dissent. “The truth is more complicated.”

Justice Scalia read from his dissent on the bench, a step justices take in a small share of cases, typically to show that they have especially strong views.

Justice Kennedy, in his opinion, wrote that the law was “unconstitutional as a deprivation of the equal liberty of persons that is protected by the Fifth Amendment.”