Martin ended it in the ninth when he sent Jon Rauch's 3-2 slider into the left-field seats, but the Yankees first put up two runs in both the seventh and eighth innings, turning a 3-0 Mets lead into a 4-3 deficit.
The Mets led by one when they turned to Bobby Parnell out of the bullpen in the eighth, but he allowed consecutive singles to Derek Jeter, Curtis Granderson, Mark Teixeira and Alex Rodriguez before exiting with a deficit.
Jeter set the tone, singling up the middle and taking second when Omar Quintanilla could not field his ground ball and let it roll into no-man's land in shallow center.
"Of course it's playable," Collins said of the ball ruled a single to start the inning. "It's Derek Jeter, give him a hit. Get him closer to 4,000."
The Yankees singled their way around the bases to their first lead in the eighth, behind hit No. 3,166 for their captain, but it was Martin who started the comeback with a two-run homer in the seventh. It came only after David Wright made a throwing error on an Andruw Jones ground ball that would have ended the inning, and Niese's day, after seven scoreless innings.
"It bothers me any time I make an error, but it's part of the game," said Wright, who struck out along with Jason Bay to leave the bases loaded in the second. "I got to the ball, I just couldn't get a very good grip on it. On defense, you try to pick your pitchers up and you hope that your pitcher can pick you up. In this case, Russell hit a good pitch."
Niese's line remained untarnished -- seven innings, no earned runs and six strikeouts -- but Martin's two-run blast that sneaked past a leaping Scott Hairston and bounced off the top of the right-field wall brought the Yankees' lineup to life.
"It feels rough," said Hairston, who doubled and scored to start the Mets' three-run second inning. "Every team goes through their ups and downs, and we just had our downtime."
They still responded in the top of the ninth, which started with consecutive doubles from Lucas Duda and Ike Davis, who came on in the eighth as a defensive substitute.
Davis' at-bats Saturday encouraged Collins, but the manager did not want to get ahead of himself with the slugger mired in a season-long slump and 17-year veteran left-hander Andy Pettitte on the mound. A start for Davis might do more harm than good, Collins reasoned, but he hopes now that the good that comes from Davis' game-tying double to the left-center-field gap lasts longer for Davis than it did for the Mets.
Only one batter later, Davis was out at third on a fielder's choice as Quintanilla was unable to advance the runner with no outs and the score tied.
Two men remained stranded that inning, and only one came to bat for the Yankees in the ninth. After Mets mistakes extended the game, Martin ended it.
"Their miscues led to some runs for us -- the two-run homer and then that extra run," said Yankees manager Joe Girardi. "That's going to happen from time to time."