Tracy Schmaler, a spokeswoman for the Justice Department, said federal officials were reviewing the decision and had no further comment. But lawyers for the plaintiffs said they fully expected the Obama administration to appeal. An appeal would be heard by the First Circuit, which also includes Rhode Island, Maine, New Hampshire and Puerto Rico.

In the case brought by Attorney General Martha Coakley, Judge Tauro found that the 1996 law, known as the Defense of Marriage Act, or DOMA, compels Massachusetts to discriminate against its own citizens in order to receive federal money for certain programs.

The other case, brought by Gay and Lesbian Advocates and Defenders, focused more narrowly on equal protection as applied to a handful of federal benefits. In that case, Judge Tauro agreed that the federal law violated the equal protection clause of the Constitution by denying benefits to one class of married couples  gay men and lesbians  but not others.

Neither suit challenged a separate provision of the Defense of Marriage Act that says states do not have to recognize same-sex marriages performed in other states. But if the cases make their way to the Supreme Court and are upheld, gay and lesbian couples in states that recognize same-sex marriage will be eligible for federal benefits that are now granted only to heterosexual married couples.

“This court has determined that it is clearly within the authority of the commonwealth to recognize same-sex marriages among its residents, and to afford those individuals in same-sex marriages any benefits, rights and privileges to which they are entitled by virtue of their marital status,” Judge Tauro wrote in the case brought by Ms. Coakley. “The federal government, by enacting and enforcing DOMA, plainly encroaches upon the firmly entrenched province of the state.”