WASHINGTON (Reuters) - The Obama administration decided on Tuesday to appeal a judge’s rulings that prevented the U.S. government from banning same-sex marriages, a move that could undermine support among President Barack Obama’s traditional liberal base ahead of a key election.

The Obama administration filed a notice of appeal with the U.S. District Court for the District of Massachusetts in support of the 1996 Defense of Marriage Act, or DOMA, that barred gay marriages, even though Obama had previously opposed the law.

Although Obama opposes the law, a Justice Department spokeswoman said that the administration was defending the statute because it was obligated to defend federal laws when challenged in court.

“As a policy matter, the President has made clear that he believes DOMA is discriminatory and should be repealed,” said Justice Department spokeswoman Tracy Schmaler. “The Justice Department is defending the statute, as it traditionally does when acts of Congress are challenged.”

The rulings being appealed by the government were made in July by U.S. District Judge Joseph Tauro in Boston who found the law violated the U.S. Constitution’s 10th Amendment, which protects states’ rights, and the clause granting equal protection under the law.

Under his rulings, same-sex couples would be entitled to the same federal spousal benefits and protections that are afforded to heterosexual married couples.

One of the challenges was brought by the state of Massachusetts and the other by several couples, including an employee of the U.S. Postal Service, Nancy Gill, who could not obtain coverage for her wife, Marcelle Letourneau, on her family health and vision plans.

The appeal comes at a tough time for Obama, who has been trying to shore up his liberal base ahead of the contentious congressional elections when his fellow Democrats are expected to lose many seats to Republicans. Democrats could lose control of the House of Representatives.

A key concern has been whether those who have supported Obama in the past will show up to vote in the November 2 midterm elections. He has opposed same-sex marriages but supported civil unions and extended some benefits to gay partners of federal employees.

Gay rights activists have argued that the legal battle is one for equal rights while their opponents, including religious conservatives, have argued same-sex marriages are a threat to the traditional family.

Massachusetts was the first state to legalize same-sex marriages and has been followed by a handful of other states. The state attorney general, Martha Coakley, said they would defend the district court ruling at the appeals court.

“DOMA is an unjust, unfair and unconstitutional law that discriminates against Massachusetts married couples and their families,” she said in a statement.

A lawyer for the Gay & Lesbian Advocates & Defenders (GLAD) organization, which represented Gill in the challenge, said they are confident in the strength of their case.

“DOMA brings harm to families like our plaintiffs every day, denying married couples and their children basic protections like health insurance, pensions, and Social Security benefits,” Mary Bonauto, GLAD’s Civil Rights project director, said in a statement.