The sinking feeling was only temporary this time. After Casey McGehee’s grounder slipped through the right side of the infield, Detroit ran itself out of the eighth inning with a baserunning blunder, and Walker’s two-run homer in the top of the ninth gave New York a 3-1 win over the Tigers on Sunday.

The Mets victimized by back-to-back infield singles in the seventh managed to avoid a three-game sweep. Detroit lost for only the second time in 12 games.

“We’ve got to hang in there, we can’t get down, we’ve got to stay as positive as we can,” Collins said. “Hopefully, we start getting a few guys back and make a good run.”

The injury-plagued Mets had allowed Detroit to tie the game at 1 in the seventh with the help of a couple fluky infield hits. Then the Tigers put men on first and second with two outs in the eighth. McGehee slapped a grounder that deflected off Loney and into shallow right field, but J.D. Martinez stopped at third instead of coming around to score.

Justin Upton, who had started the play on first, kept going toward third, leaving two Detroit runners in the vicinity of the same base. Right fielder Curtis Granderson patiently ran the ball all the way in, and Martinez was eventually tagged out in a rundown.

“J.D. has his back to the play, so he sees it get knocked down and he’s thinking he has to stop. By that time, if he tries to start up again and go, he’s out by 20 feet,” Detroit manager Brad Ausmus said. “There’s no blame here. Justin looked back and saw the ball got through, so he’s thinking that J.D. saw the same thing. J.D. didn’t.”

New York retook the lead when Walker went deep off Francisco Rodriguez (1-2). The Mets still trail NL East-leading Washington by nine games, but they’re very much in the thick of the race for the wild cards.

Detroit trails AL Central-leading Cleveland by two games.

Anibal Sanchez pitched eight impressive innings for the Tigers, and Jacob deGrom was strong for the Mets. Addison Reed (3-2) got the win in relief, and Jeurys Familia pitched the ninth for his major league-leading 39th save in 41 chances.

New York’s 1-0 lead didn’t last long after Conforto’s drive. With runners on first and second and two outs in the bottom of the seventh, Andrew Romine hit a dribbler toward third and the Mets had no play. That was it for deGrom, who was replaced by Jerry Blevins.

Pinch-hitter Ian Kinsler then hit a soft chopper that made it past the mound for another infield single, tying the game.

Rodriguez hit Alejandro De Aza with a pitch to start the ninth, and Walker followed with a drive to right-center.

“Guys are doing a really good job of not worrying about who’s hurt, who’s behind them, what’s going on, what their numbers say,” Walker said. “They’re really focused in on each night, and that’s important, especially this time of year.”

Sanchez allowed a run and four hits, striking out 10 with no walks.

DeGrom gave up a run and seven hits in 6 2/3 innings.

Doubling up

The Mets hit into three double plays in the final four innings in a loss Saturday night. On Sunday, it was Detroit’s turn to waste scoring chances. The Tigers grounded into double plays in the first, second and fourth.

Trainer’s room

Mets: SS Jose Reyes (left oblique strain) is scheduled to play in a simulated game Monday in Florida. ... De Aza had a wrap around his right wrist after the game but said he was OK and expects to be ready for his team’s next game.

Your online hub for high school sports!

Sign up for The Whistle, the GametimeCT newsletter, to get the best, most up-to-the-minute, engaging high school sports coverage in the state.