SAN FRANCISCO — The seagulls hovering above the left-field grandstand had company in the 16th inning Thursday night as Pete Alonso took a mighty cut and pushed the Mets to the brink of uncharted territory for this season.

But Alonso’s tie-breaking home run only made what awaited all the more unbearable. Rookie Chris Mazza, the last available pitcher in the Mets’ bullpen, never got an out in the bottom of the inning. And so the Mets’ hopes of their first five-game winning streak in 2019 ended with Donovan Solano’s RBI single that gave the Giants a 3-2, 16-inning victory at Oracle Park.

Mazza, who had thrown 34 pitches the previous day, was in his second inning of work on a night when the teams combined to leave 24 runners on base.

“Everyone in the lineup today and our entire pitching staff showed so much heart,” Alonso said.

The Mets fell eight games below .500, a step backward after closing their series in Miami with two victories and then winning two straight in Minnesota.

“We dug ourselves a hole and we need to win, it’s as simple as that,” Alonso said.

Alex Dickerson started the winning rally with a leadoff double. Brandon Crawford’s ensuing double — culminating an 11-pitch at-bat — tied it before Austin Slater was drilled by a pitch and Kevin Pillar’s single loaded the bases for Solano.

Manager Mickey Callaway said if the game had extended and a pitching change was needed, he would have used J.D. Davis on the mound and placed Jacob deGrom in left field. But the Giants jumped Mazza before it could get to that.

“I made three mistakes in that last inning and they took advantage of every single one,” Mazza said.

If Madison Bumgarner’s brilliance for nine innings wasn’t enough, the Mets couldn’t touch the Giants’ bullpen until Alonso’s blast in the 16th.

The Mets had their chance in the 15th, putting the go-ahead run at second base with one out, but neither Jeff McNeil nor Davis could deliver against lefty reliever Williams Jerez.

In the 10th, the Mets also wasted an opportunity after Amed Rosario’s double put runners on second and third with nobody out. Lefty Will Smith escaped by striking out Tomas Nido, Michael Conforto and McNeil to keep it 1-1.

Bumgarner received a standing ovation from the crowd after pitching nine innings in which he allowed one earned run on five hits and one walk over 94 pitches. The veteran left-hander, who might be the most accomplished starting pitcher potentially available before the July 31 trade deadline, surrendered only three hits over his final eight innings.

The Giants are among the hottest teams in MLB, with 13 victories in their past 15 games. Entering play, the Giants’ 25-15 record was tied for third-best in the NL since June 1, behind only the Nationals and Braves.

Noah Syndergaard lasted seven innings in this one and allowed one earned run on eight hits with eight strikeouts and one walk. It was his strongest performance since firing a shutout over seven innings against the Rockies on June 9.

Mike Yastrzemski’s triple leading off the seventh tested Syndergaard’s mettle, but the right-hander escaped, most notably striking out Bumgarner, who was allowed to bat with runners on the corners and one out. Syndergaard remained in the game following a visit from Callaway to retire Brandon Belt for the final out in the seventh.

Syndergaard was threatened early, but the Giants couldn’t break through against him until the fourth, when they loaded the bases and received a sacrifice fly from Pillar that tied it 1-1.

Pablo Sandoval, Crawford and Yastrzemski all singled in the inning against Syndergaard. And Pillar’s drive to left nearly caused a problem for Davis, who made a leaping catch to prevent additional runners from scoring as Sandoval waltzed home.

The Giants wasted Dickerson’s leadoff triple in the second inning, as Syndergaard struck out Crawford and Yastrzemski before getting Pillar to pop out. In the third, Belt smashed a two-out double to center before Syndergaard retired Buster Posey.

McNeil smashed Bumgarner’s first pitch of the game for a double, went to third on Davis’ ensuing single and scored as Alonso grounded into a double play. Davis’ hit was the Mets’ last until the fifth, when Nido doubled with two outs.