SAN FRANCISCO -- San Francisco Giants pitcher Yusmeiro Petit threw 14 or more pitches in an inning just twice in his near-perfect game earlier this month.
Saturday, he threw 14 to the same batter, and in the end it wound up costing him his perfect record.
Tommy Medica hit the 14th pitch of an epic at-bat up the middle for an RBI single, triggering a two-out, four-run rally in the fourth inning that propelled the San Diego Padres to a 9-3 win over Petit and the Giants.
Eric Stults overcame an early home run by Hunter Pence to record his third consecutive win as the Padres (76-85) assured themselves of no worse than a third-place tie in the final National League West standings.
By winning for just the second time in San Francisco in eight games this season, San Diego moved ahead of San Francisco (75-86) by one game with just Sunday's series finale remaining.
"Very enjoyable win," Padres manager Bud Black said. "We've had some good innings this season. This (Saturday's fourth) was a good one."
The Padres broke open a tight game with a four-run ninth that included Jedd Gyorko's 22nd home run of the season, a two-run shot off Giants left-hander Mike Kickham. Only two rookie second basemen have hit more homers.
But it was the fourth that swung the game in San Diego's favor.
Previously unbeaten Petit (4-1) retired all 11 Padres he faced after Chris Denorfia's game-opening home run until Chase Headley doubled with two outs in the fourth.
That set up the most critical at-bat of the game, a 14-pitch duel between Petit and Medica, a product of nearby Santa Clara University. The rookie first baseman won the battle, smacking Petit's 14th pitch into center field for an RBI single that got the Padres within one, 3-2.
"He kept throwing good pitches and I was lucky to stay alive," Medica said. "I finally got one in play."
Petit never recovered. Four pitches later, Jesus Guzman gave the Padres a lead they would never relinquish with a two-run homer to left field.
Alexi Amarista, Chris Robinson and Stults followed in quick fashion with singles, the pitcher's hit driving in Amarista to cap the four-run inning and end Petit's afternoon.
"Tommy's was one of the best at-bats of the year," Black said. "Petit was throwing him everything. All pitches. All locations. All velocities. And he won the battle.
"The dugout's always saying, 'Win it. Win it. Win it.' And he did."
Petit, who gave up just 12 runs in his first six starts of the season, surrendered five runs on seven hits in 3 2/3 innings Saturday. He struck out two and did not walk a batter.
"He was throwing the ball well. The big inning might have caught up with him, in particular the long at-bat," Giants manager Bruce Bochy said. "He couldn't get the ball where he wanted and he started making mistakes."
Stults (11-13), who had been 0-6 since the All-Star break before his three-game win streak, surrendered a run in the San Francisco first on a pair of doubles, then fell behind 3-1 on Pence's two-run shot in the third, his 27th of the season.
Pence had more than just his homer to celebrate Saturday. Before the game, he signed a five-year contract worth $90 million. The right fielder had been scheduled to become a free agent after Sunday's finale.
Stolts allowed three runs on seven hits in seven innings. The left-hander retired the last nine batters he faced, finishing with no walks and three strikeouts.
"Obviously this is the way I wanted to end it," Stults said. "It's been a season full of ups and downs. At the end of the year, it's easy to give in. I made some adjustments four starts ago. Fortunately, it worked."
Angel Pagan, who doubled to lead off the Giants' first and scored the club's first run, had three of San Francisco's nine hits.
Five Giants relievers held the Padres scoreless on three hits through the eighth inning before San Diego's four-run explosion. Denorfia had his second RBI of the game with a single in the six-hit uprising, while Medica and Guzman capped three-hit efforts with two-out singles.
The Padres finished with 16 hits. All nine starters had at least one hit.
Bochy assured the Giants will play to win with third place on the line Sunday.
"It'd be nice to win (Sunday)," he said.
NOTES: The only second basemen to hit more than 22 home runs as rookies were Florida's Dan Uggla (27) in 2006 and the New York Yankees' Joe Gordon (25) in 1938. ... Padres OF Will Venable, who did not start because of a strained left abdominal muscle, pinch-hit in the ninth and ignited the four-run inning with a double. He immediately left the game for a pinch-runner. ... The win was San Diego's 76th of the year, matching last season's total. ... Pence will become the only major-leaguer to start all 162 games this season if he, as expected, starts Sunday's finale. ... The 27 home runs are a career-high for Pence. No Giant has hit more than 27 homers in a season since LF Barry Bonds had 28 in 2007.