So many times Sunday, the Mets appeared vulnerable, on the brink of ceding another game in the standings.

Michael Cuddyer butchered a fly ball in leftfield that led to the tying run in the seventh. Manager Terry Collins got burned for entrusting the game to rookie Hansel Robles instead of Tyler Clippard.

And for all of his dominance this season, closer Jeurys Familia sweated out a tense ninth inning, allowing the tying run to stand just 90 feet away.

But by hanging on to a 5-4 victory over the Red Sox, the Mets exhibited their tendency to rebound, a valuable trait should they reach the playoffs for the first time since 2006.

"This was a big game for us," Collins said after a win that kept the Mets' lead over the Nationals at 5 1/2 games. "We've been flat the last couple of nights. To come out today, tremendous crowd support today, fans' support, it was a good win for us."

After returning to Citi Field on a seven-game winning streak, the Mets promptly dropped consecutive games to the last-place Red Sox, who nearly made it a clean sweep. But a half-inning after Cuddyer let the tying run score on his misplay in leftfield, he knocked in the winning run with a clutch single.

Daniel Murphy scored, though only after getting himself into scoring position with a surprise steal of second base, a play that Collins called "the biggest play of the game."

"That was a huge moment," Cuddyer said of Murphy, who had stolen just one base all season. "Obviously picked the right time to go. Sneak attack. Nobody even covered. That was big."

Clippard worked 1 1/3 scoreless innings, bailing Robles and the Mets out of trouble in the seventh before turning it over to Familia, who stranded the tying run at third base in the ninth.

"You never want to get swept," Clippard said. "But we're playing good, we knew that, and we proved it today."

Twice, the Mets let leads slip away.

Red Sox slugger David Ortiz wiped away a 1-0 deficit in the sixth, blasting a two-run homer off righthander Noah Syndergaard, who allowed four runs in 6 2/3 innings. Then in the seventh, after going ahead 4-2 on Juan Uribe's two-run double and a run-scoring single by Anthony Recker, the Red Sox clawed back again.

With Syndergaard still on the mound, pinch-hitter Jackie Bradley Jr. ripped a ground-rule double to score Blake Swihart. Bradley later swiped third base and scored when Cuddyer got a late read on Mookie Betts' shallow fly ball off Robles, who entered in relief.

Collins brought in Clippard, who struck out Pablo Sandoval to keep the score tied at 4. But it didn't stay that way long.

After reaching on a fielder's choice, Murphy made a bold decision. With two outs, he ran on reliever Heath Hembree.

"I was watching him warm up and he seemed he might be a little bit slow to the plate," Murphy said. "Sometimes, relievers will come in and the first one, they'll just want to execute the pitch, then they'll quicken up."

Murphy's timing proved impeccable. He ran on the first pitch. And as planned, he put himself in position to score. Cuddyer followed by gaining some redemption. His third hit of the game proved to be the biggest.

"To be a good team, you have to do that," said Cuddyer, who is hitting .375 since returning from a knee injury. "You have to have a short memory, and you have to be able to rebound."