Neil Walker had gone through similar struggles before. So when Mets manager Terry Collins approached him with the idea of a mental health break — as a way to break what had been a horrendous slump — the second baseman obliged.

“Sometimes the best medicine is to just get out of your own way,” said Walker, whose go-ahead three-run homer in the seventh inning helped the Mets beat the Rockies, 6-4, on Sunday at Citi Field.

All wins are crucial, especially for teams such as the Mets (54-50), who are fighting to keep their heads above water while leading the league in MRIs. Citi Field has become a den of clenched teeth and frayed nerves, all as the Mets scramble to improve themselves before Monday’s 4 p.m. non-waiver trade deadline.

But the victory carried even more weight for a club that had saved its most uninspired baseball for the week leading up to that deadline. A loss would have been their fifth in a row and would have clinched a four-game sweep for the Rockies, who had vaulted themselves back into the fringes of contention at the Mets’ expense.

But the Mets spared themselves, even though it came at great cost. This time it was starting shortstop Asdrubal Cabrera, who had to be helped off the field, felled by a patellar tendon strain in his left knee as he rounded third base and scored in the first inning.

advertisement | advertise on newsday

Cabrera could become the sixth member of the Mets’ Opening Night lineup to land on the disabled list. Meanwhile, the Mets insist that they can avoid making Yoenis Cespedes the seventh, though he was held out of action Sunday with lingering soreness in his right quadriceps.

Playing with a compromised lineup, the Mets nonetheless rallied from a one-run deficit in the seventh to secure a big win just before the start of the Subway Series tonight. “It’s a huge win for us,” Collins said.

The Mets moved within 6 1⁄2 games of the NL East-leading Nationals and remained 2 1⁄2 games behind the Marlins in the race for the second wild card.

Addison Reed pitched a scoreless eighth and Jeurys Familia closed it out in the ninth, earning his first save since blowing back-to-back opportunities after a streak of 52 straight regular-season saves dating to last year. “For me, it was really important to go back out there and pick up my game,” he said.

Noah Syndergaard threw a career-high 118 pitches in six innings, allowing three runs (two earned) and six hits. He again was cursed by a high pitch count and blamed himself for trying to aim his pitches rather than letting them fly. But he had kept his team in the game. And in the seventh, when Carlos Gonzalez lifted a sacrifice fly to put the Rockies ahead 4-3, the Mets responded quickly.

Mets videos

With two outs and a man on first, James Loney worked a walk after a tense 10-pitch at-bat and Walker stepped to the plate looking for his third hit of the game.

A 2-for-39 stretch had dropped his average from .262 to .237, and he recently was given a three-day breather from the starting lineup. But Walker has since caught fire, going 12-for-19.

On Sunday, he tripled home a run, singled and blasted his three-run shot in the seventh off Boone Logan. When he reached the plate, Walker beamed as Loney lifted the batting helmet from his head in celebration, a duty that has typically been left for Cabrera.

Moments later, the fans roared, stopping only when Walker obliged their demand for a curtain call.

Said Collins: “The days off that we gave him kind of let him ease his mind a little bit.”

advertisement | advertise on newsday