“We knew he would be tough,” Yankees Manager Aaron Boone said of Lugo.

Lugo was relieved by Robert Gsellman, who retired the Yankees in the seventh and then, with one out and a runner on first in the top of eighth, induced pinch-hitter Aaron Judge, who was supposed to have the night off, to hit a grounder to short.

Amed Rosario flipped the ball to Reyes for the apparent force at second, with Judge then safe at first when Reyes threw wide of the bag. A replay appeal by the Yankees, however, revealed that Reyes had never touched second base. So instead of an inning-ending double play, there were now Yankees on first and second, and the go-ahead run was in the batter’s box with still just one out. In a season of many miscues by the Mets, including a lineup that batted out of order, Reyes’s double blunder seemed destined to send the Mets to another defeat. Instead, Gsellman, bearing down, got Gleyber Torres to foul out and Brett Gardner to fly out to left.

Then came the top of ninth, when the Mets got fortunate again. With one out and Greg Bird on first and Anthony Swarzak on the mound, Gary Sanchez lined a bullet right at Frazier, who caught it and then doubled off Bird.

Game over, Mets win, as unlikely as it all seemed when the game began. And even with the victory, the Mets improved to just 28-34, in fourth place in the National League East, 7½ games behind the first-place Washington Nationals and still carrying concerns about their struggling lineup.

And in a reflection of those concerns, the Mets, after the game, released Adrian Gonzalez, the 36-year-old former All-Star first baseman who was traded by the Los Angeles Dodgers to the Atlanta Braves in the off-season before the Braves ultimately released him. That, in turn, allowed the Mets to sign Gonzalez for the major league minimum. But Gonzalez hit only .237 in New York, and to fill his spot the Mets will recall 22-year-old Dominic Smith, their No. 1 pick in the 2013 draft. Smith was stuck back in Class AAA Las Vegas this season after making a limited major league debut in 2017 that included nine home runs but a meager batting average of .198.

Now he could get another chance to impress.

As for Cabrera, he seemed to slip after grounding back to Severino while leading off the Mets’ half of the first inning. He was slow returning to the dugout and was the last Met to join his teammates on the field for the top of the second. But he remained in the game for two more innings, and grounded out in the bottom of the third, before leaving the game in the top of the fourth. There was no immediate word on whether he, too, was headed to the disabled list, which is already bloated with Mets.

In addition to Cespedes and Syndergaard, center fielder Juan Lagares, the utility man Wilmer Flores and closer Jeurys Familia are all on the D.L. The woes are many for the Mets, but on Sunday night, they at least found a way to beat their imposing Bronx rivals.