SAN FRANCISCO — This version of the Giants can never be counted out of a game.

Overcoming a rare below-average night from Tim Hudson and game-long struggles with men on base, the Giants rallied in the ninth inning for a 5-4 walk-off win over the New York Mets on Saturday.

“It just tells you about what kind of team we have,” said Michael Morse, the hero of the night who delivered the game-winning hit. “We find a way. We’ve been doing it all year. We’ve been fighting till the last out.”

The game-winning rally started in the unlikeliest way — with a strikeout.

Angel Pagan struck out leading off the bottom of the ninth, but the strikeout pitch squirted away from Mets catcher Anthony Recker. He recovered, but threw wide to first base and Pagan beat it out.

Hunter Pence followed that up by ripping a double down the left field line, driving home Pagan with the tying run.

“Pagan had a heck of a game,” manager Bruce Bochy said of his center fielder, who had three hits. “You strike out, sometimes you have a tendency to get frustrated and not get down the line. But he busted his tail down the line to beat that throw. That’s where it all started.”

Pence moved to third when Buster Posey flew out to deep left field. After Pablo Sandoval was intentionally walked, Morse sent one sailing in Triples Alley to deliver another unlikely victory.

The Giants moved a season-high 20 games over .500 at 41-21 and now own a 9½ game lead in the National League West over the Los Angeles Dodgers.

The game-winning rally took starter Hudson off the hook. He never seemed to have his best stuff, but battled throughout and left after five innings trailing 3-0. He allowed season highs of nine hits and three walks and the five innings pitched was his second-shortest outing of the season, topped only by his three-inning stint in Colorado that was interrupted by rain.

“Huddy was a little off today,” Bochy said. “He battled his tail off to keep us in the game. What a job he did to hold them to three runs.”

The Giants threatened often throughout the night. They put at least two runners on base in four of the first six innings and had a bases-loaded, no-out situation in the fifth. They got just one run out of that — on a Posey double-play grounder.

San Francisco loaded the bases again in the sixth and Pagan delivered a two-run single to make it 4-3. But Posey struck out with the bases loaded to end the inning.

But thanks to the ninth-inning heroics, those frustrations were easily forgotten.

Giants reliever Santiago Casilla threw a 30-pitch bullpen session and could begin a rehabilitation assignment as soon as Wednesday. Casilla, on the disabled list since May 22 with a hamstring strain, will be re-evaluated after his next bullpen session Monday.

Brandon Belt, out since May 10 with a broken thumb, has ramped up some of his conditioning work and Bochy said he could resume baseball activities within the next week.

The Giants used 16 of their 30 selections on the final day of the draft on pitchers, grabbing 11 right-handers and five southpaws. Over the three days, 20 of their 40 picks were pitchers, including Vanderbilt righty Tyler Beede, the No. 14 overall pick.

They took two Bay Area products on the final day in St. Francis-Mountain View catcher Timothy Susnara (34th round) and Drake-San Anselmo pitcher Joe Ryan (39th round). They also grabbed catcher Benito Santiago, the son of the former Giant who was the 2002 NLCS MVP, in the 38th round.

Otto Warmbier was arrested in January 2016 at the end of a brief tourist visit to North Korea. He had been medically evacuated and was being treated at the University of Cincinnati Medical Center when he died at age 22.