SAN FRANCISCO — Yoenis Cespedes launched his third homer in two games, then engaged in an elaborate high-five celebration with Neil Walker. Noah Syndergaard pumped his fist, exuding sheer delight, when he got a double play late in his best start in weeks.

Everywhere they looked Sunday night, the Mets left hints of a renaissance, beating the Giants, 2-0, to salvage a split of this four-game series. But mostly, the Mets conveyed that they have yet to give up on their season.

“I just hope that everyone has it in their head that we can keep going out there, we can keep winning and have fun and keep playing well,” said Cespedes, whose two-run homer in the seventh inning was the difference on a night that belonged to the pitchers.

Whether the window has slammed shut on the Mets is a matter of debate. They are 4 1⁄2 games behind the Cardinals for the second wild-card spot and are in St. Louis for three games starting Tuesday night.

Some projections give the Mets less than a 10-percent chance of sneaking into the postseason. If they are to make a run, it will begin with the likes of Ces pedes and Syndergaard, two of their brightest stars.

advertisement | advertise on newsday

“We’ve had a tough time,” manager Terry Collins said. “But if you’re going to win, your good players have to play good. What Noah did tonight, what Ces has done the last couple of games, we ride those guys. Hopefully, this is the start of what we’ve been looking to do. We’re getting some guys back and we’ve got to keep working.”

Cespedes’ 25th homer, a two-run shot to left, jolted the Mets to life after they had been stifled by Giants righthander Jeff Samardzija (10-9). He entered the seventh with a no-hitter.

Syndergaard (11-7) allowed two hits in eight innings in one of his most dominant outings of the season. His fastball roared in the triple digits and he wiped out hitters with his slider. He struck out six and walked two.

“For the past month and a half, I feel like it was the first time I felt relaxed and had fun out there,” said Syndergaard, who has been prone to high pitch counts. “I kept things simple. The past month and a half, I’ve been trying to think too far ahead in advance.”

When Syndergaard needed only 98 pitches to get eight innings in the books, Collins’ first inclination was to send him back out for the ninth. But Syndergaard swallowed his pride for the good of the team, letting Collins know that he was battling fatigue.

Mets videos

“He showed me something,” Collins said, impressed by the 23-year-old’s show of maturity.

The decision paid off. Jeurys Familia nailed down his 41st save, surviving a pinch-hit single by Buster Posey. For only the second time since the first week of July, the Mets won consecutive games.

Said Syndergaard: “I thought it would be just the best decision to hand it over to the best closer in the game and get a win, get back on the bus and go back to St. Louis.”

Syndergaard, who walked, was the only Mets baserunner through six innings. Slick defensive plays took a pair of possible hits away from Jose Reyes. Then Curtis Granderson led off the seventh with a double to leftfield over the head of Gregor Blanco and Cespedes deposited a 1-and-0 pitch over the leftfield fence.

“I haven’t had anybody where the ball comes off the barrel of the bat like that,” Collins said of Cespedes, who has made an impact since coming off the disabled list Friday.

advertisement | advertise on newsday

Meanwhile, Syndergaard got some help in what became a tense game.

Because of his slow times to home plate, opposing baserunners have exploited him, swiping 40 bases in 44 chances entering play. Veteran backup Rene Rivera has become his batterymate, mostly because of his ability to control those runners

Syndergaard, who cut down his leg kick to reduce his time to the plate, reaped the benefits of a more streamlined delivery as Rivera caught two runners attempting to steal.

The reward was clear. Syndergaard won consecutive games for the first time since June.

“It feels like a sense of tunnel vision,” he said. “Those eight innings, it just felt like it was me and Rene out there.”