Mets first baseman Pete Alonso tosses his bat after popping...

Mets first baseman Pete Alonso tosses his bat after popping out with runners on base against the Giants during the 13th inning at Oracle Park in San Francisco on Thursday. Credit: EPA-EFE/Shutterstock / John G. Mabanglo

SAN FRANCISCO — A long night and dramatic 16th inning ended in immense disappointment for Chris Mazza and the Mets.

Mazza, a Bay Area native appearing in his fourth major-league game, was in line for his first win until the Giants came back for a walk-off win, 3-2. Consecutive doubles by Alex Dickerson and Brandon Crawford (11-pitch at-bat) tied the score before Donovan Solano ended it with a single past a diving Pete Alonso. 

Alonso mashed his 32nd homer through a flock of seagulls in the top of the inning, positioning the Mets for what would have been a fifth straight win. Fighting to get back to the fringe of the playoff picture, the Mets are 44-52 and trail eight teams for the second National League wild-card spot.

“Everyone today showed a lot of heart, a lot of fight,” Alonso said. “Sometimes you don’t come up on the winning end of it.”

For Mazza, a starter for Triple-A Syracuse most of the year, appearing in relief in consecutive games was highly unusual. He threw 34 pitches in two innings against the Twins on Wednesday and was the last reliever available Thursday.

“I feel it a little bit, but you still gotta go out and try to make pitches to the best of your ability,” said Mazza, 29, who estimated he hadn’t pitched on back-to-back days in a half-decade. “I thought I did that. I thought I made some good pitches when I needed to. Made three mistakes in that last inning, and they took advantage of every single one.”

Said manager Mickey Callaway: “It’s difficult. You’re not used to it. But it was a necessity tonight.”

This one got weird. The only Mets not to get into the game were Jacob deGrom, who will start Friday, and Jason Vargas, who started Wednesday. Callaway said that if the game continued beyond Mazza’s effort, J.D. Davis would have pitched and deGrom would have played leftfield. Dominic Smith played the final five innings in rightfield, his first major-league appearance at the position.

Six Mets relievers tossed six scoreless innings in relief of Noah Syndergaard (seven innings, one run) before Mazza entered. The bullpen has a 2.16 ERA (four earned runs in 25 innings) in six games to begin the second half.

Madison Bumgarner, Giants legend and trade candidate, dominated for nine innings and just 94 pitches. He allowed one run and five hits, walked one and struck out six. Manager Bruce Bochy said Bumgarner lobbied heavily to pitch the 10th.

The only run he allowed came in the first, when Jeff McNeil (first-pitch double) and Davis (single) opened the game with consecutive hits. McNeil scored when Alonso grounded into a double play. The Mets didn’t get another hit until there were two outs in the fifth, when Tomas Nido doubled.

Bumgarner finished his night with Todd Frazier’s groundout to shortstop. Surrounded by trade rumors as the rebuilding Giants move toward selling in advance of the July 31 deadline, Bumgarner walked off the Oracle Park mound to a standing ovation.

“I don’t give a (expletive),” Bumgarner told reporters of trade rumors. “I’m here to win games for this team, and that’s what I’m doing.”

Matching Bumgarner most of the night was Syndergaard, who struck out eight and walked one, scattering six hits. He twice stranded a runner after a leadoff triple: Dickerson in the second and Mike Yastrzemski in the seventh.

Like he did in Miami last weekend, Syndergaard had his slider working again. He held the Giants to 1-for-9 with runners in scoring position. He left the ballpark before speaking to reporters after the Mets’ stunning loss.

“I’m sure they felt frustrated at one point too,” Callaway said. “They were feeling better than us right now.”