SAN FRANCISCO (AP) The San Diego Padres rallied from six runs down and nearly spoiled San Francisco's delayed clinching party.
The Giants blew a six-run lead, and then rallied for a 9-8 victory over the Padres on Thursday night to stay within one game of Pittsburgh for the top spot in the NL wild-card standings.
''I'm very proud of the guys, down 6-0, come back 8-6 against a good team, a team going to the playoffs,'' Padres manager Bud Black said. ''It doesn't matter if it's game 159 or game 1, our guys play, man. It doesn't matter what game. That's the mantra of this group, they keep playing.''
Hunter Pence scored the go-ahead run on Matt Duffy's squeeze bunt in the Giants' three-run seventh, hours after they clinched a playoff berth with Milwaukee's loss at Cincinnati. Pablo Sandoval had a season-high four RBIs, including a key single in the decisive seventh.
The Giants (86-73) kept pace with Pittsburgh (87-72) after the Pirates won 10-1 at Atlanta to pull within one game of first-place St. Louis in the NL Central. San Francisco will play one of those two clubs in a one-game playoff Wednesday, home field still to be determined. Lefty 18-game winner Madison Bumgarner is expected to start.
''The fun's just now starting,'' right-hander Tim Hudson said.
Yasmani Grandal hit his first career grand slam for San Diego in the seventh. He also had a solo shot in the sixth.
Two batters after Grandal's slam, Rene Rivera went deep to give the Padres an 8-6 lead. The Giants then answered in the bottom half against Blaine Boyer (0-1).
Tim Lincecum (11-9) recorded the final out of the seventh for the win. Santiago Casilla closed it out for his 18th save in 22 chances.
Lincecum earned his 100th career victory on all of two pitches.
''It's kind of the vulturish way but I'll take anything I can get,'' Lincecum said. ''Who would plan for a two-pitch win?''
Grandal had his second career multihomer game, also accomplishing the feat on June 30, 2012, at Colorado.
Brandon Belt and Brandon Crawford each hit a solo homer and Sandoval produced his biggest day of 2014.
Before the game, Giants manager Bruce Bochy said his players would celebrate their first playoff berth since winning the 2012 World Series. Once San Francisco came back to win, that could be done with a bit more fervor.
Belt splashed a home run into McCovey Cove leading off the second, the 68th time a Giants player homered into the bay beyond the right-field arcade and the fourth by Belt.
Crawford hit his career-best 10th home run in the fourth against Andrew Cashner.
''Their game plan was definitely different than the other night,'' Cashner said. ''I made some good pitches here and there but overall I kind of missed location for the most part. I had more balls overall up in the zone than down in the zone.''
Sandoval hit a sacrifice fly and a trio of RBI singles as the Giants won for the 11th time in their last 13 home games. Now they are hoping a successful weekend will earn them a home date for Wednesday's one-game wild-card playoff.
San Francisco's Yusmeiro Petit was in line to end a two-start losing streak, but the Giants couldn't hold a 6-0 lead.
Will Venable hit a two-run homer in the sixth and Grandal connected two batters later to chase Petit.
San Diego, coming off an 8-2 homestand that included a three-game sweep of the Giants last weekend, needs one victory over the Giants this weekend for its first season series win since 2010.
Hall of Famer Willie Mays rode through the ballpark in a 1931 Lincoln Phaeton and tossed baseballs into the crowd during the middle of the fourth inning to celebrate the upcoming 60th anniversary of his historic over-the-shoulder catch from Game 1 of the New York Giants' 1954 World Series against Cleveland at the Polo Grounds.
Padres: OF Cameron Maybin was scratched with what Black called a ''health issue,'' but it wasn't considered serious. ... RHP Odrisamer Despaigne won't pitch again this season. The Cuban defector, a rookie, has a sore right side. ''We felt that the risk of throwing him out there this weekend was not worth it based on his side session the other day when he still felt a little discomfort,'' Black said. ''He's thrown the ball extremely well. It's a great learning experience for him to pitch in the United States in the major leagues. The talent is there to be successful here and that has shown through his outings.''
Giants: CF Angel Pagan underwent season-ending surgery to repair a bulging disk in his back. All went smoothly and he will remain hospitalized in Southern California initially. Recovery is expected to take about three months.
Padres: RHP Ian Kennedy (12-13, 3.76 ERA) looks to win his third straight start in his final outing of the year.
Giants: RHP Ryan Vogelsong (8-12, 3.96 ERA) makes his 32nd start, his most in a single season. He lost last Sunday in San Diego, but owns a 3-0 record and 1.89 ERA in three starts against the Padres at AT&T Park.