Rights activists hailed the opinion, saying it was a "historic and joyful" day for New Mexico and the United States, more than a third of whose states have now legalized same-sex unions.
"As a state, we have always strived to treat all families with dignity and respect, and today?s decision allowing loving, committed same sex couples to marry continues that tradition," said Laura Schauer Ives, legal director of the American Civil Liberties Union of New Mexico.
Over 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," she said.
"This truly is a historic and joyful day for New Mexico," she added.
In its 31-page opinion, published on the Albuquerque Journal's website, the state's top court said: "All rights, protections, and responsibilities that result from the marital relationship shall apply equally to both same-gender and opposite-gender married couples."
"We hold that the state of New Mexico is constitutionally required to allow same-gender couples to marry, and must extend to them the rights, protections, and responsibilities that derive from civil marriage under New Mexico law," wrote justice Edward Chavez.
New Mexico joins 16 other US states and the US capital city Washington, DC in legalizing same sex marriage. The other states are: California, Connecticut, Delaware, Hawaii, Illinois, Iowa, Maine, Maryland, Massachusetts, Minnesota, New Hampshire, New Jersey, New York, Rhode Island, Vermont, and Washington.
Marriage laws are governed by individual US states, 29 of which have amended their constitutions to ban same-sex marriage.
Efforts to give same-sex couples the same rights as heterosexuals have gathered steam in recent years.
One of the most important victories was when the US Supreme Court in June struck down the Defense of Marriage Act, which defined marriage as between one man and one woman.