WASHINGTON -- The U.S. appeals court in Boston became the first such court to strike down as unconstitutional the federal Defense of Marriage Act, ruling Thursday that it unfairly denies equal benefits to legally married same-sex couples.

The ruling is a victory for gay-rights advocates and the Obama administration, which had refused to defend that part of the 1996 law.

The decision sets the stage for a ruling next year by the Supreme Court on the constitutionality of the law that limits federal recognition of marriage to the union of a man and a woman.

The Boston-based judges stressed their decision did not establish a national right to gay marriage. That issue remains a matter for the states, they said.

But in states such as Massachusetts, where gays and lesbians can legally marry, the federal government cannot deny these couples the right to file a joint federal tax return or to receive a survivor’s benefit under the Social Security Act, the appeals court said.

The court’s opinion said there are more than 100,000 legally married gay and lesbian couples in the half-dozen states that have legalized same-sex marriages.

Congress passed the Defense of Marriage Act in 1996 to prevent same-sex marriages in one state from being legally recognized by all states. Usually, a couple’s marriage in one state is recognized as valid in all states. However, the federal law said no state “shall be required to give effect” to a “relationship between persons of the same sex.” Moreover, it said that under federal law, a marriage “means only the legal union between one man and one woman.”

The case decided Thursday dealt only with this latter provision involving federal law and benefits.

In 2003, the Massachusetts state high court became the first to declare that gays and lesbians had an equal right to marry. Several years later, seven same-sex couples who were married in Massachusetts filed a lawsuit in federal court challenging as unconstitutional the part of the Defense of Marriage Act that denied them the same benefits as other married couples. The state of Massachusetts filed a similar suit against the federal government, stressing this was a states-rights issue.

The Justice Department defended the law, but U.S. District Judge Joseph Tauro ruled in 2010 that it was unconstitutional to deny equal benefits to the same-sex couples who had sued. The government appealed to the 1st Circuit Court in Boston, but the Obama administration then switched sides.

President Obama and Atty. Eric H. Holder Jr. announced they would not defend the denial of equal federal benefits to legally married same-sex couples. The Justice Department then filed a brief urging the 1st Circuit to strike down the federal-benefits provision of the legislation.

House Republicans, led by Speaker John Boehner, hired Washington attorney Paul Clement to defend the law in the Boston court.

Thursday’s opinion in Massachusetts vs. U.S. Department of Health and Human Services was written by Judge Michael Boudin, an appointee of President George H.W. Bush. It was joined by Chief Judge Sandra Lynch, a Clinton appointee, and Judge Juan Torruella, a Reagan appointee.

In the key passage, the judges stressed they were upholding a state’s right to insist on equal treatment for its married couples.

“To conclude, many Americans believe that marriage is the union of a man and a woman, and most Americans live in states where that is the law today. One virtue of federalism is that it permits this diversity of governance based on local choice, but this applies as well to the states that have chosen to legalize same-sex marriage,” Boudin wrote.

“Under current Supreme Court authority, Congress’ denial of federal benefits to same-sex couples lawfully married in Massachusetts has not been adequately supported by any permissible federal interest.”

david.savage@latimes.com