The New Mexico Supreme Court has ruled to allow same-sex marriage across the state.
The decision ends legal ambiguity that had produced a patchwork arrangement in which some counties permitted gay nuptials while others prohibited them.
The ruling makes New Mexico the 17th state in the United States to legalise same-sex marriage.
It comes amid growing momentum on the issue that saw the governors of Hawaii and Illinois sign bills last month to permit same-sex weddings in their states.
The court, in a unanimous ruling, found no New Mexico law that expressly forbade gay and lesbian couples the right to wed, and said that barring such marriages amounted to unlawful discrimination based on sexual orientation.
"Denying same-gender couples the right to marry and thus depriving them and their families of the rights, protections and responsibilities of civil marriage violates the equality demanded by the equal protection clause of the New Mexico Constitution," Justice Edward Chavez wrote in a 31-page opinion.
As a remedy, the court required civil marriage to be construed as "the voluntary union of two persons to the exclusion of all others," regardless of gender.
It added that the rights, protections and responsibilities of marriage would apply equally to all, in a decision that highlighted the shifting legal and social landscape on same-sex marriage in the US.
Polls have shown increasing public support for gay marriage, and civil rights groups have prevailed at a number of courthouses and in an increasing number of state legislatures.
Ten years ago, no US state permitted gay marriage.
Stepping into an intensifying and often bitter national debate over same-sex matrimony, the New Mexico Supreme Court agreed in September to settle the matter for the state after some counties began issuing marriage licenses to same-sex couples, either unilaterally or after lower-court rulings.
In one ruling earlier this year, a New Mexico judge upheld the right to gay marriage in a case that applied to counties encompassing the state's largest city, Albuquerque, and the state capital, Santa Fe.
Later, judges in a number of other counties asked clerks to justify their practice of not issuing same-sex marriage licenses.
Many clerks began issuing such licenses to same-sex couples rather than going back to court.
One of New Mexico's most vocal opponents of same-sex marriage, Republican state Senator Bill Sharer, responded to the ruling by saying he planned to introduce a constitutional amendment to ban gay marriage.
Such an amendment, if passed by the legislature, would ultimately need approval of voters.
"The Supreme Court decided to overturn a several-millennial-long standing law, and I don't think they had any good reason to do it," Mr Sharer said.
Brian Brown, president of the anti-gay marriage group the National Organization for Marriage, called the ruling "a continuation of a very dangerous rush" toward silencing those who see marriage as the union of one man and one woman.
Before the ruling, New Mexico faced a situation unique in the US because its law was ambiguous on same-sex marriage, unlike other states that expressly prohibited or permitted it.
The debate reached a crescendo when all 33 county clerks in the state joined the American Civil Liberties Union in petitioning New Mexico's high court to decide the issue on a state-wide basis.
Eight New Mexico counties were processing marriage applications by same-sex couples ahead of the ruling, said ACLU of New Mexico spokesman Micah McCoy.
Laura Schauer Ives, legal adviser for the group, said the ruling marked "a historic and joyful day for New Mexico."
The ruling was tailored to take effect immediately, and same-sex couples in at least three counties that had previously not issued licenses to gay and lesbian couples called their local clerk's office to ask about obtaining one, said Daniel Ivey-Soto, executive director of the county clerks affiliate of the New Mexico Association of Counties.
Couples can wed the same day they get a license.