A man who failed Massachusetts’ bar exam and then brought a lawsuit claiming that he failed because he refused to answer a question related to same-sex marriage has apologised to the gay community.

In a letter to Boston paper Bay Windows Stephen Dunne called his legal action misguided.

“I have regrettably perpetuated intolerance and animosity towards my fellow Americans,” he wrote.

“My religiously-based discrimination of gay people was callous and diametrically opposed to America’s core principles of freedom and equality.”

A question came up in Mr Dunne’s bar exam last year concerning the rights of two married lesbians, their children and their property.

He claimed the question itself was “morally repugnant,” because it legitimises same-sex marriage and parenting, which he opposes.

He narrowly failed his exam, scoring a 268.866. The pass grade is 270.

Massachusetts legalised same-sex marriage in 2003.

The exam question read:

“Yesterday, Jane got drunk and hit (her spouse) Mary with a baseball bat, breaking Mary’s leg, when she learned that Mary was having an affair with Lisa.

“As a result, Mary decided to end her marriage with Jane in order to live in her house with (children) Philip (and) Charles and Lisa. What are the rights of Mary and Jane?”

Mr Dunne had asked a federal court to back his argument that the test violated his rights and targets his religious beliefs. He was seeking $9.75 million (£4.86m) in damages.

He later withdrew his lawsuit, reportedly because the July bar exam did not include a question on same sex marriage.