WASHINGTON - The U.S. appeals court in Boston became the first appeals 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 groundbreaking ruling is a victory for gay rights advocates and the Obama administration, which had refused to defend this part of the 1996 law.

The decision sets the stage for a ruling next year by the Supreme Court on the constitutionality of the federal 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 same-sex couples can legally marry, the federal government cannot deny them the right to file a joint federal tax return or to receive a survivor's benefit under the Social Security Act, the court said.

The 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.

"For me, it's more just about having equality and not having a system of first- and second-class marriages," said plaintiff Jonathan Knight, a financial associate at Harvard Medical School who married Marlin Nabors in 2006. "I think we can do better, as a country, than that."

He said the law costs the couple an extra $1,000 a year because they cannot file a joint federal tax return.

Gay marriage opponents blasted the decision. "This ruling that a state can mandate to the federal government the definition of marriage ... we find really bizarre, rather arrogant," said Kris Mineau, president of the Massachusetts Family Institute.

Congress passed the Defense of Marriage Act in 1996 to prevent same-sex marriages in one state from being legally recognized by all states. It was signed into law by President Bill Clinton. 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 ruling dealt only with the provision involving federal law and benefits.

The Massachusetts state high court became the first in 2003 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 law that denied them the same benefits as other married couples. The state of Massachusetts -- led by state Attorney General Martha Coakley -- filed a similar suit, stressing this was a state's right issue.

The Justice Department defended the law, but U.S. District Judge Joseph Tauro ruled in 2010 that it was unconstitutional. The government appealed to the 1st Circuit, but the Obama administration then switched sides and said it would not defend the denial of equal federal benefits to married same-sex couples. Republicans, led by Speaker John Boehner, then hired attorney Paul Clement to defend the law.

The opinion was written by Judge Michael Boudin, an appointee of President George H.W. Bush, and was joined by Chief Judge Sandra Lynch, a Clinton appointee, and Judge Juan Torruella, a Reagan appointee. They stressed they were upholding a state's right to insist on equal treatment for its married couples.

"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. "... Congress' denial of federal benefits to same-sex couples lawfully married in Massachusetts has not been adequately supported by any permissible federal interest."

The Associated Press contributed to this report.