SANTA FE, N.M. — New Mexico became the latest state to legalize gay marriage Thursday as its highest court declared it is unconstitutional to deny marriage licenses to gay and lesbian couples.

Justice Edward L. Chavez said in a ruling that none of New Mexico’s marriage statutes specifically prohibits same-gender marriages, but the state’s laws as a whole have prevented gay and lesbian couples from marrying. The justices said same-sex couples are a discrete group that has been subjected to a history of discrimination and violence.

“Accordingly, New Mexico may neither constitutionally deny same-gender couples the right to marry nor deprive them of the rights, protections and responsibilities of marriage laws, unless the proponents of the legislation — the opponents of same-gender marriage — prove that the discrimination caused by the legislation is ‘substantially related to an important government interest,”‘ Chavez wrote.

New Mexico joins 16 other states and the District of Columbia in allowing gay marriage either through legislation, court rulings or voter referendums.

Eight of the state’s 33 counties started issuing marriage licenses to same-sex couples in August when a county clerk in southern New Mexico independently decided to allow the unions.

County officials had asked the high court to clarify the law and establish a uniform state policy on gay marriage.

State statutes don’t explicitly prohibit or authorize gay marriage. However, county clerks historically have denied marriage licenses to same-sex couples because the law includes a marriage license application with sections for male and female applicants.

The ruling was a victory for gay rights activists who had been unable to win a legislative resolution of the issue.

“This truly is a historic and joyful day for New Mexico,” ACLU-New Mexico Legal Director Laura Schauer Ives said. “The more than 1,000 same-sex couples who have already married in New Mexico can now rest certain knowing their marriages will be recognized and respected by our state.”

The American Civil Liberties Union and the National Center for Lesbian Rights represented same-sex couples in the Supreme Court case. They contended gay marriage must be allowed because of constitutional guarantees of equal protection under the law and a state constitutional prohibition against discrimination based on sexual orientation.