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 has been a horrendous slump — the veteran second baseman obliged.

“Sometimes, the best medicine is to just get out of your own way,” said Walker, whose go-ahead three-run shot in the seventh inning pushed the Mets to a 6-4 victory over the Rockies.

All wins are crucial, especially for teams such as the Mets (54-50), who are fighting to keep their heads above water despite 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 the deadline.

But the victory carried even more weight for a club that had saved its most uninspired baseball for the week leading up to Monday’s nonwaiver trade deadline.

A loss would have been their fifth in a row and would have clinched a four-game sweep to the Rockies, who 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 was helped off the field, felled by a strained patellar tendon in his left knee as he rounded third base to score.

Now, after leaving the game following the first inning, it’s possible that Cabrera becomes the sixth member of the Mets’ Opening Night lineup to land on the disabled list. Meanwhile, the Mets insist that they can avoid making slugger Yoenis Cespedes the seventh, though he was held out of action on Sunday with lingering soreness in his banged-up right quad.

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 on Monday.

“It’s a huge win for us,” Collins said.

The Mets trail the Nationals by seven games in the NL East but stayed within reach of the wild card, 2 1/2 games behind the Marlins.

Addison Reed pitched a scoreless eighth inning and Jeurys Familia closed it out in the ninth, his first save since blowing back-to-back opportunities, ending his streak of 52 straight saves dating back to last year.

“For me, it was really important to go back out there and pick up my game,” Familia said.

Noah Syndergaard threw a career-high 118 pitches in six innings, allowing three runs (two earned) on six hits. Again, he was cursed by high pitch counts, blaming himself for trying to aim his pitches rather than letting them fly.

But he had kept his team in the game. In the seventh, when Carlos Gonzalez lifted a sac fly to put the Rockies ahead 4-3, the Mets responded quickly.

Kelly Johnson reached on a fielder’s choice, 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.

Walker had been the coldest bat in the Mets’ lineup. When he was recently given a three-day breather from the starting lineup, his average had plummeted to .239. But Walker has since caught fire, going 13-for-22.

On Sunday, he tripled home a run, singled and then 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.”