The Lobos (17-8, 6-6 Mountain West Conference), had lost three in a row and five of six as the team struggled through injuries and off-the-court issues.
Hunter Maldonado led the Cowboys (6-19, 1-12) with 21 points.
Although New Mexico controlled most of the first half, Martin turned the momentum around late when the Lobos led 29-24. First he picked up a loose ball after a scramble and dropped a 3-pointer and on the ensuing possession, he made a clean steal and took it down for a resounding dunk, sparking a half-closing 11-5 run for New Mexico.
"At the beginning of the game, you could see that we were working through a lot of things -- new guys, a little rusty," New Mexico coach Paul Weir said. "The offense wasn't quite there. We turned the ball over a lot early on. But the defense just kept us in the game. We really, really guarded for the first 20 minutes of the game."
The second half was marked by a red-hot streak for Vance Jackson, who scored 14 straight Lobos points, knocking down four 3-pointers in the stretch.
When the New Mexico shots started to fall, there was little the Cowboys could do about it, Wyoming coach Allen Edwards said.
"We know that this was a team that takes tough shots," he said. "If they see a couple go in, the rim gets bigger and they play with more emotion. The crowd gets into the game so you're putting yourself at a disadvantage, but when Jackson starting making jab 3s, I thought that just opened it up for them as a group."
Wyoming: The Cowboys are all but playing out the string, mired three games back in the loss column in the conference basement.
New Mexico: The Lobos have a chance to make some big steps up in the conference standings as their three remaining home games are against the teams immediately ahead do them: UNLV, Nevada and Utah State.
The game marked the return of New Mexico starter Jackson, who missed four games because of a leg injury, and JaQuan Lyle, who missed two games because of a leg injury and two games because of suspension.
And that made everbody else on the floor better.
"It slides everybody down the depth chart so to speak," Weir said. "They're out there taking those bullets and allows those other guys to come into less pressure situations. They have different guys guarding them. The reality is JaQuan and Vance are going to be guarded by two of the (opponent's) better players."
New Mexico dominated the boards, holding a 29-13 rebounding advantage at halftime, including 11-0 on the offensive end, leading to a 14-0 margin in second-chance scoring.
"I thought not taking care of the glass in the first gave them a lift," Edwards said. "And it showed more so in the second half."
Wyoming: The Cowboys are at home February 15 against Colorado State.
New Mexico: The Lobos play at No. 4 San Diego State on February 11. The Aztecs won the teams' first meeting two weeks ago 85-57.
For more AP college basketball coverage: https://apnews.com/Collegebasketball and http://twitter.com/AP-Top25
No. 2 Baylor wins again without Drew, routing Washington
— Baylor assistant coach Jerome Tang is directing the Bears while head coach Scott Drew is in a 10-day isolation period after testing positive for COVID-19.
Withers scores career-high 20, Louisville tops Prairie View
— Jae'Lyn Withers scored a career-high 20 points, David Johnson added 19 and Louisville defeated Prairie View A&M 86-64 Sunday night, winning its first three games of the season.
Russell lifts Rhode Island over San Francisco 84-71
— Fatts Russell had 21 points, going 11 for 11 from the foul line, and Rhode Island beat San Francisco 84-71 on Sunday.