SAN FRANCISCO -- Neither the San Francisco Giants nor San Diego Padres had the type of season they envisioned six months ago.
That made a season finale in which both teams walked away feeling pretty good about themselves all the more improbable Sunday.
Francisco Peguero hit his first major league home run, a game-tying shot to lead off the bottom of the ninth inning, and Hunter Pence drilled a game-winning RBI single four batters later as the Giants overcame a Jedd Gyorko grand slam to beat the Padres 7-6.
The come-from-behind win allowed the Giants (76-86) to tie the Padres (76-86) for third place in the final National League West standings. San Francisco, which won the World Series last year, earned 18 fewer regular-season wins than in 2012, the second-biggest drop-off among all major league teams.
That didn't stop the Giants from celebrating after Sunday's victory.
"This game was a great way to go into the offseason," said Pence, who before the game hosted a press conference to formally announce his signing of a five-year, $90 million contract. "We found a way to win it."
The Giants did so despite the best efforts of Gyorko, who capped arguably the greatest season in baseball history by a rookie second baseman with a fifth-inning grand slam, propelling the Padres into a 6-2 lead.
However, San Diego never scored another run against five Giants relievers, including Barry Zito, who made an eighth-inning cameo in what is expected to be his final game for San Francisco.
"Zito really pumped us up," Pence said of the left-hander's four-pitch strikeout of former Oakland A's teammate Mark Kotsay to end the eighth inning.
The sellout crowd erupted into the type of standing ovation Zito was denied in what is expected to be his final start as a Giant on Wednesday night. The team almost surely will buy out the final year of his contact this offseason at a cost of $7 million, ending the seven-year, $126 million relationship.
"You could tell he was excited. It was powerful," Pence said. "We came into the dugout, and everyone could feel it."
Peguero entered the game under unfortunate circumstances in the top of the ninth. He replaced left fielder Gregor Blanco, who suffered a sprained right ankle when he collided with center fielder Angel Pagan while chasing Will Venable's pinch-hit triple.
With the Padres up 6-5, closer Huston Street (2-5) got ahead of the rookie 1-2, but Peguero blasted his homer into the first row of the bleachers in left-center field. The home run came on Peguero's 45th big-league at-bat.
Street faced four other Giants and didn't get any of them out. Pence was the fourth, lacing a full-count, bases-loaded drive to straightaway center field for the game-winner that scored Tony Abreu, who singled to immediately follow the homer.
"I'm tremendously excited to be back. (The contract signing) definitely lifted my spirits," Pence said after finishing the season as the Giants' leader in home runs (27) and RBIs (99). "I want to earn every bit of it."
Sergio Romo (5-7) pitched around Venable's triple to record the win with a scoreless ninth inning.
Gyorko's grand slam, his second homer of the three-game series, came on the third pitch thrown by Giants reliever Jake Dunning. Alexi Amarista, Chris Denorfia and Jesus Guzman also scored on the blast, which turned 2-2 tie into four-run Padres advantage.
"That was exciting," he said of the game as a whole. "You never want to lose like that, but that's going to happen."
The home run was Gyorko's 23rd of the season, the third most all-time among second basemen. Only the Florida Marlins' Dan Uggla (27 in 2006) and the New York Yankees' Joe Gordon (25 in 1938) hit more as a rookie second baseman.
Gyorko finished the season with 63 RBIs, tops on the Padres. No other rookie second baseman ever led his team in RBIs.
The 25-year-old also played a flawless game in the field to finish the year with a .992 fielding percentage, the best ever for a rookie second baseman. He made only four errors all season, the fewest among second basemen who played at least 108 games.
Gyorko said he's proudest of his defense.
"There were a lot of questions coming into the year whether I could handle second," he said. "I take great pride in my defense. I'm pretty happy with the year, but there's always room for improvement."
Neither starting pitcher factored in the decision. The Giants' Guillermo Moscoso, named earlier this week to replace Matt Cain as Sunday's starter, was charged with five runs on four hits and four walks in 4 1/3 innings. He struck out four.
The Giants rallied after Padres starter Tyson Ross left following six effective innings with a 6-3 lead. Ross gave up two run-scoring doubles to Brandon Belt among three runs allowed on seven hits. He struck out seven and walked just one.
Pence, Abreu, Belt and Pablo Sandoval had two hits apiece for the Giants, who outhit the Padres 11-7.
Chris Denorfia had three hits, including a double, and Nick Hundley smacked a solo homer, his 13th, for San Diego.
NOTES: Pence started all 162 games this season, the only major-leaguer to do so. ... Playing in the final game of his 17-year career, Kotsay started in right field and went 0-for-4, capped by the strikeout against Zito. ... Padres 3B Chase Headley announced before the game that he is scheduled to undergo surgery Tuesday to repair a torn meniscus in his left knee. ... The Giants won the season series from the Padres 11-8. San Francisco prevailed in the season series against all of its NL West rivals for the third consecutive year. ... The Giants sold out every home game for a third straight season. Their season attendance total exceeded 3.3 million. ... Both teams will open the 2014 season on March 31. The Padres will host the 2013 NL West champions, the Los Angeles Dodgers, while the Giants will visit the second-place Arizona Diamondbacks.