The court however stopped short of ordering the state to start issuing marriage licences to same-sex couples.
In a 4-3 ruling that could make Massachusetts the first state to legalise gay marriage, the Supreme Judicial Court on Tuesday said the state may not deny the rights conferred by civil marriage to two individuals of the same sex who wish to marry.
"We declare that barring an individual from the protections, benefits, and obligations of civil marriage solely because that person would marry a person of the same sex violates the Massachusetts Constitution," the court said in its ruling.
The court said the ruling would be on hold for 180 days to allow the state legislature to take any action it may deem appropriate.
Gay marriages are forbidden in the United States, although one state, Vermont, allows same-sex civil unions - contracts that essentially provide most of the legal rights and protections of marriage but under a different name.
A civil union is only recognised in the state in which it is granted while a marriage is recognised nationwide, experts said.
Debate over the issue of same-sex unions has intensified since Canada has taken steps to legalise gay marriages and the US Supreme Court in June struck down state sodomy laws.
Conservative critics had said the Supreme Court's ruling could open the door to same-sex marriages in the US.
The 1996 Defence of Marriage Act, signed by former President Bill Clinton, defines marriage for federal purposes as between one woman and one man.