After a 6-0 lead quickly turned into an 8-6 deficit, it appeared the Giants' postgame celebration would awkwardly follow a loss, but a three-run bottom of the seventh inning ensured nothing but positive vibes would ensue shortly after.
Sandoval's fourth RBI of the game pulled the Giants within one, and a Brandon Belt single tied the game two batters later. Matt Duffy followed with a perfectly executed safety squeeze to score Hunter Pence and give the Giants what would hold as the winning run.
Tim Lincecum, who retired Alexi Amarista on two pitches to end the seventh, earned the win, the 100th of his career.
"It's great and all," Lincecum said of his 100th victory, "but with everything that's been going on today with getting into the playoffs, that's a bit more special."
Manager Bruce Bochy met with lineup cornerstones Pence, Buster Posey and Sandoval before the game to gauge whether rest would behoove the trio in advance of next week's playoff game. They declined, wanting to be in Thursday's lineup, and they produced early. Posey hit a one-out single to move Joe Panik to third base in the first, and Sandoval drove him in with a sacrifice fly to left.
Posey doubled to deep center in the third to score Gregor Blanco. Sandoval followed with a single to score Posey.
The middle-of-the-order productivity sandwiched Belt's first home run since Aug. 3. He turned a 94 mph fastball from Andrew Cashner into his fourth career splash hit -- and the Giants' 68th all-time -- in the second.
"It feels good just to be back on the field with the guys," said Belt, who recently returned from his latest lengthy stint on the disabled list. "Fortunately I was able to put a few good swings out there and help the team win. That makes you feel good."
Brandon Crawford added a solo shot in the fourth inning. It was his 10th of the season, a career high. Another Sandoval single scored Posey again in the fifth to stretch the lead to 6-0.
Starter Yusmeiro Petit was cruising along for the Giants until the sixth inning. Will Venable got the Padres on the board with a two-run shot, and two batters later, a solo shot off the right-field foul pole by Yasmani Grandal narrowed the Giants' lead to 5-3 and knocked Petit out of the game. His final stat line read three earned runs on five hits with eight strikeouts in 5 1/3 innings.
Facing Jean Machi with the bases loaded in the seventh, Grandal hit a grand slam to give the Padres a 7-6 lead. Two batters later, Rene Rivera added a solo shot off Machi.
The come-from-behind win snapped the Giants' three-game losing streak to the Padres.
"Weird," Blanco said when describing Thursday night's game. "What I like is that we went through it, even knowing we had clinched. We didn't take it for granted, went out there and took care of business."