The Obama administration will contest a Massachusetts ruling which says the Defence of Marriage Act (DOMA) is unconstitutional.

In July, a judge in the state ruled that the law, which bars federal government from recognising gay marriage, should be repealed.

President Obama called the law “abhorrent” in his 2008 election campaign but his spokeswoman said the government was obliged to defend federal laws when challenged in court.

According to Reuters, Justice Department spokeswoman Tracy Schmaler said: “As a policy matter, the President has made clear that he believes DOMA is discriminatory and should be repealed.

“The Justice Department is defending the statute, as it traditionally does when acts of Congress are challenged.”

Massachusetts, which was the first US state to legalise gay marriage, is also the first state to challenge the law in court.

District Judge Joseph Tauro in Boston found that it violated states’ rights to recognise marriage as they wish, and also equality provisions in the Constitution.

DOMA restricts recognition of marriage to heterosexual couples. It means that gay married couples cannot access federal rights and benefits, such as those relating to healthcare.

Massachusetts attorney general Martha Coakley said the state would defend the ruling at an appeals court.

Legal experts have said that if the ruling is upheld by a higher court, it could have far wider implications and encourage more states to challenge DOMA.