As the 10th inning unfolded, Matt Harvey said, he looked over to where Jordany Valdespin was sitting as the Mets kept putting runners on and Valdespin was “nice and loose, joking around, talking with the guys,” Harvey said.

Why shouldn’t Valdespin be relaxed during a tense sequence? He seems to have a knack for dramatic moments and proved it again Wednesday, smashing a walk-off grand slam to lift the Mets to a 7-3 victory over the Dodgers and help preserve Harvey’s perfect record at 4-0.

It was a rewarding win for the Mets. They won on a night that Harvey, their ace, said, “In my mind, I sucked” — even though that’s not really true — and they blew a bundle of scoring chances.

“When you have your ace on the mound and he leaves the game and you’re getting beat, you don’t know what’s going to happen,” Mets manager Terry Collins said. “So to come back and win a game like that is going to be huge for us moving forward.”

Valdespin, who beat Jonathan Papelbon and the Phillies with a ninth-inning homer last season, was greeted at the plate by a giddy mob of teammates after slugging a 2-1 pitch from Josh Wall over the right-field wall. Later, John Buck smacked a celebratory “pie” into Valdespin’s face.

“He hit a good hard shot, he deserved a good hard pie,” the catcher said. “I promised him next time I’d go a little softer.”

It was the sixth walk-off grand slam in Mets history and the first since Kevin McReynolds hit one against Montreal on June 25, 1991. It was also the first slam of Valdespin’s career.

“I’m very excited, it’s the second time I hit a homer to win the game,” a grinning Valdespin said.

“Everybody’s happy.”

It never would’ve happened if not for two big moments an inning earlier, when the Mets went into the ninth trailing, 3-2. Mike Baxter led off with a sinking liner to left that hit the heel of Carl Crawford’s glove. When Baxter saw it kick away, he decided to try for second, and his hustle double set up David Wright’s tying RBI single. Before Wright’s hit, the Mets had been just 1-for-12 with runners in scoring position in the game.

“The way Baxter took second base, at that moment, you kind of knew we were going to win that game,” Harvey said.