Mets shortstop Jose Reyes reacts after he hits a walk-off...

Mets shortstop Jose Reyes reacts after he hits a walk-off RBI single against the St. Louis Cardinals at Citi Field on Thursday, July 20, 2017. Credit: Kathleen Malone-Van Dyke

It is a play that is practiced in the earliest days of spring training, with the hope that it becomes hard-wired into the brain. Nothing is foolproof, though, which is why Jose Reyes and the Mets could smile at the end of a 3-2 walk-off victory against the Cardinals on a steamy Thursday afternoon at Citi Field.

With two down, runners on the corners, and the score tied at 2, Reyes pulled a grounder down the first-base line. First baseman Matt Carpenter gloved it. Pitcher Trevor Rosenthal got a late start and failed to cover the bag in time, and Reyes easily beat Rosenthal to the base with a headfirst slide.

Yoenis Cespedes scored from third base and the Mets emptied out of their dugout and doused Reyes just past t first base. In a season filled with disappointment, this was a gift.

“I saw the first baseman playing way back. I said in my mind if you hit something there, hustle to first base,” Reyes said. “When I saw the pitcher, he stood on the mound for like two seconds. I knew it was going to be tough for him to get to first base.”

Indeed, manager Terry Collins acknowledged that it was only through a fluky mistake that the Mets emerged with a win after nearly wasting a strong outing by Seth Lugo.

“If the pitcher comes off the mound right away,” Collins said, “I don’t think [Reyes] makes it.”

Lugo took a no-hitter into the fifth inning, when it was broken up by Greg Garcia’s two-out double. But the righty ran into fatigue, an area he must improve to better handle the rigors of pitching deep into games.

“It defines a good pitcher from a bad pitcher,” Lugo said. “I feel like everybody can go out and get somebody once. To do it two times, three times, four times, that’s what separates from the average to the elite.”

Lugo allowed one run. It came in the sixth on Tommy Pham’s double that tied the score. To that point, the Mets’ only run had come from Lucas Duda, who went deep in the second for his 17th homer.

But Pham struck again in the eighth, this time crushing a go-ahead homer off Erik Goeddel to give the Cardinals a 2-1 advantage.

Wilmer Flores came off the bench to save the Mets, tying it in the bottom half with a solo shot off lefty Brett Cecil. Displaced as the starter at third base by T.J. Rivera, Flores hadn’t homered since June 24.

“My goal is to stay ready, and whenever I’m in there, try to always contribute,” Flores said.

In the ninth, the Mets rallied once more. Michael Conforto walked, Cespedes bounced into a forceout, and Duda flew out. With the Mets one out from extra innings, Rivera delivered a clutch single, setting the table for Reyes.

Said Rivera: “I try to slow it down and just try to have a good at-bat.”

Moments later, the Mets were celebrating a win that meant little in the standings but confirmed something that was already known. After 2 hours, 47 minutes of sweating through 92 degrees and smothering humidity, it is far better to have a win to show for it at the end.

The Mets are 43-50 and 11 games back of the wild card, far from even the fringes of contention. The victory merely salvaged a series split against the Cardinals.

Still, for the Mets, any win is appreciated.

“We needed one,” Collins said. “We’ve had a lot of them slip away lately.”