SAN FRANCISCO — Earlier this season, Jacob deGrom ducked into the clubhouse in the middle of a game, one that happened to be broadcast by Hall of Fame pitcher John Smoltz. Right then, Smoltz mentioned how for 10 years in his career, he threw an additional bullpen session in between starts.

DeGrom had done the same in 2015 but had since gotten away from the practice. A few days later, he texted Smoltz and changed his preparation, sticking with it even after he hit one of the worst patches of his career.

On Saturday night, during the Mets’ 5-2 victory over the Giants, deGrom proved the virtue of sticking with the new routine.

In eight brilliant innings, he showed pinpoint command of his secondary pitches, which made his fastball even harder to hit. Rarely did he miss a spot, part of the reason the Giants mustered only one run and four hits, with the only damage a solo homer by Brandon Belt in the seventh.

“That’s what I want to do every time out there,” said deGrom (7-3). “It’s kind of what I expect from myself and I think that’s why those other ones were so frustrating — going out there and not find a way to get outs.”

Time may have run out for the Mets, a reality acknowledged by a front office that has let it be known that the club will listen to trade offers for its veterans. But if they are to maintain any hope of a miraculous run, it will begin with the kind of pitching that deGrom delivered against the Giants.

advertisement | advertise on newsday

In his previous two outings, deGrom allowed one run in a complete-game win over the Cubs on June 12, then gave up an unearned run in eight innings in a victory over the Nationals on June 18. Now deGrom has a 0.72 ERA in his last three games.

In the two outings immediately before that, he allowed 15 earned runs, 18 hits and six walks in eight innings, raising concern about whether he had fully bounced back from elbow surgery.

“He’s come back after that, made the necessary adjustments and has been lights out,” Jay Bruce said. “That’s what an ace does. It’s come to the point now where I’m always wondering if he’s going back out in the ninth inning to finish the game.”

DeGrom brought up Smoltz when asked how he turned around his season. “We just talked about the idea behind it,” he said of the conversation.

For more than a month, deGrom has thrown two bullpen sessions between each start. Even during his rough patch, he figured that the extra work — done at lighter intensity — would pay off with improved command. He was right.

Mets videos

“His slider and his curveball were really as good as they’ve been,” manager Terry Collins said. “He’s starting to pitch.”

After dropping three of four to the Nationals and losing four straight to the Dodgers, the Mets (33-41) assured themselves of a series victory against the Giants (27-50).

Johnny Cueto held the Mets to one run in seven innings, but the Giants’ bullpen let the game get away, allowing two runs in each of the last two innings.

Curtis Granderson led off the eighth with a triple and scored on Bruce’s single to snap a 1-1 tie. Wilmer Flores, who had a solo homer in the fourth, added an RBI double.

Jose Reyes led off the ninth with a triple and scored on a single by pinch hitter Michael Conforto, who batted for deGrom. Conforto scored on a wild pitch.

advertisement | advertise on newsday

One day after Asdrubal Ca bre ra asked to be traded — his forceful response after the Mets surprised him with a move from shortstop to second base — he only improved his stock. In his second start at second, he collected his second multihit game and made a diving stop to take away a hit.