SAN FRANCISCO >> The baseball popped out of Ha-Seong Kim’s glove and breathed new life into the Giants’ stagnant offense.

The Padres shortstop failed to place the tag on Jorge Soler as he slid into second base, and moments later, the big-bodied designated hitter was chugging across home plate after a Matt Chapman single to score the go-ahead run in a hard-nosed 3-2 win Sunday afternoon in the rubber game against the NL West foes.

Soler should have been the final out of the eighth inning, after Michael Conforto bounced a would-be double-play grounder to Jake Cronenworth at first base. He tagged the bag to record one out and fired to second in time to nab Soler, but the ball bounded out of Kim’s glove and into center field.

“Sometimes you need a little luck, too,” manager Bob Melvin said.

Camilo Doval closed the door in the top of the ninth to earn his first save of the season and secure the Giants’ second come-from-behind win with a margin of just one run over the course of the three-game series.

Before Jung Hoo Lee raced home on a ground ball out to get the Giants on the board in the sixth inning, they had gone 15 2/3 frames without scoring a run since Thairo Estrada’s walkoff double in the bottom of the ninth Friday night. They had mustered only three hits against a steady diet of knuckleballs from Matt Waldron, the Padres’ fifth starter, until Wilmer Flores and Soler broke through with a pair of base hits against Johnny Brito to begin the rally in the bottom of the eighth.

Even while winning two of three, the Giants scored six total runs.

The win was only the Giants’ second in their past seven games, averaging only three runs over that stretch while taking a .188/.283/.302 batting line as a team over their previous six games into Sunday’s series finale.

“Our offense is going to come around,” Melvin said, pointing to the track record of his players. “But if we can do the little things right and create this little identity and win these types of games, I think we’ll be tougher for it. Across the board, really, nobody’s swinging great.”

It was nearly the same old story for Logan Webb, who pitched well but was in line for the loss until the eighth inning comeback.

Using a couple of well-timed double-play balls scooped up by the left side of his infield, Webb pitched around 10 Padres hits to limit the star-studded lineup to two runs over seven innings, rebounding nicely from his last start, when he failed to complete five innings for only the second time in the past two seasons.

Webb returned to the same formula in the seventh to escape his thorniest jam, generating back-to-back ground balls — one that Nick Ahmed shoveled for a force out at second and another picked by Chapman — after allowing the first two batters of the inning to reach base.

“That’s something I kind of lacked my last outing,” Webb said. “I got into try to strike everybody out mode, and I’m not that guy. As much as I wish I was, I think getting into the dugout and getting the bats going as fast as I can is the most important thing.”

In his past six starts against the Padres, Webb has allowed seven earned runs, a 1.44 ERA, but the win was only the Giants’ third in those games.

“As long as the team wins, I’m all good,” Webb said.

Watching Conforto’s ground ball bounce up the first base line, Webb said the reaction in the dugout, “was like, ‘Damn!’ at first. Then the ball came out and we were all screaming in there. It was exciting.”

The last time Webb faced the Padres at Oracle Park was last September, when he twirled the second complete game of his career in a 2-1 win. Opposing him was Blake Snell, who held the Giants scoreless for seven innings as he made his case for the Cy Young.

“We’ve got ’em both on the same team now,” Melvin said. “It’s a good thing.”

Up next >> Snell will make his long-awaited debut Monday to begin the Giants’ three-game series against the Washington Nationals, who have RHP Trevor Williams (1-0, 3.38), RHP Josiah Gray (0-2, 14.04) and LHP Patrick Corbin (0-1, 6.97) lined up to start the three games in that order. Kyle Harrison (1-1, 4.91) and Jordan Hicks (1-0, 0.75) will round out the home stand before the Giants travel across the country for six games in Florida.