The issue is expected to be decided by the Supreme Court. The decision came less than a month after the court heard arguments on Sept. 27.
Lawyer Paul Clement, who had argued in support of the law on behalf of the Bipartisan Legal Advisory Group of the House of Representatives, was traveling and did not immediately return a message for comment.
James Esseks, an attorney for the American Civil Liberties Union, called the ruling "a watershed moment in the legal movement for lesbian and gay rights."
"It's fabulous news for same-sex couples in New York and other states," he said.
Esseks said the 2nd Circuit went farther than the appeals court in Boston by saying that when the government discriminates against gay people, the courts will presume that the discrimination is unconstitutional.
In striking down the law, the Jacobs wrote that the law's "classification of same-sex spouses was not substantially related to an important government interest" and thus violated the equal protection clause of the Constitution.
He said the law was written so broadly that it touches more than a thousand federal laws. He said "homosexuals are not in a position to adequately protect themselves from the discriminatory wishes of the majoritarian public."
He rejected arguments that the definition of marriage was traditional.
"Even if preserving tradition were in itself an important goal, DOMA is not a means to achieve it," he said.
Judge Chester Straub dissented, saying that if the government was to change its understanding of marriage, "I believe it is for the American people to do so."
"Courts should not intervene where there is a robust political debate because doing so poisons the political well, imposing a destructive anti-majoritarian constitutional ruling on a vigorous debate," he said.
The ruling came in a case brought by Edith Windsor. She sued the government in November 2010 because she was told to pay $363,053 in federal estate tax after her partner of 44 years, Thea Spyer, died in 2009. They had married in Canada in 2007.
The law, which denies federal recognition of same-sex marriages and affirms the right of states to refuse to recognize such marriages, was passed by Congress and signed by President Bill Clinton after it appeared in 1993 that Hawaii might legalize gay marriage. Since then, many states have banned gay marriage but several have approved it, including Massachusetts and New York.