SAN FRANCISCO (AP) -- One more strike. Another couple of feet on a line drive.
That's all that stood between Yusmeiro Petit and one of the most unlikely perfect games in history.
Petit lost his bid for a perfect game on Eric Chavez's pinch-hit single with two out in the ninth, and then recovered to retire the final batter in the San Francisco Giants' 3-0 victory over the Arizona Diamondbacks on Friday night.
''It doesn't get any closer than that,'' Giants manager Bruce Bochy said. ''A strike away and a couple feet away from catching it. Just a beautiful game that he pitched.''
Petit (3-0) retired the first 26 batters in a remarkably efficient performance, and then got two strikes on Chavez before unleashing a tempting curveball. But the veteran third baseman laid off that 2-2 curveball that Petit was certain he would chase.
Chavez lined the next pitch to right field and Petit crouched as the ball left the bat. The Venezuelan pitcher put both hands over his head after Hunter Pence could only short-hop the ball after a valiant diving effort.
''The last two outs, it can go either way,'' Petit said through an interpreter. ''I went to 3-2 count. I just wanted to throw a good pitch. Chavez got the hit.''
Pence made a terrific catch on a similar play to help preserve a no-hitter by Tim Lincecum in San Diego on July 13. But he just missed preserving this piece of perfection.
''I gave it my best effort, but it wasn't enough,'' Pence said. ''A low liner in front of me. I felt when it was hit I was in a dream where I could not run fast enough. Off the bat it looked a little short.''
The crowd of 41,190 fans responded with a standing ovation for Petit, who struck out seven in his 95-pitch gem. A.J. Pollock grounded out to third to finish Petit's first career complete game.
Petit became the 12th player to lose a perfect game with two outs in the ninth inning and second this year, joining Texas ace Yu Darvish, who was nearly perfect against Houston in April.
''My thought is he's pitched a great game now let's break his heart,'' Arizona manager Kirk Gibson said.
Gibson picked Chavez for that task because of his experience. Chavez had never faced Petit before, but he went in the clubhouse to watch him pitch in the fifth inning to be prepared if he was needed late in the game.
''I wasn't trying to break his heart, I was trying to break it up,'' Chavez said. ''It's a pride thing.''
Before the ninth, the closest Arizona came to a hit was pitcher Patrick Corbin's sinking line drive to left that forced defensive replacement Juan Perez to make a shoestring catch for the final out of the sixth.
''Bochy called me into the game and told me it might be an interesting game for me,'' Perez said. ''Off the bat I thought it was hit harder than it was. I got a tough read on it. But I was still able to make the diving catch.''
Pence had three hits, including a home run, and scored all three runs. Brett Pill and Hector Sanchez also drove in runs.
Corbin (13-6) tossed eight strong innings, giving up eight hits. He struck out five and walked one.
Petit broke into the majors in 2006 with the Marlins, and then spent the next three years with Arizona. He was waived after the 2009 season and eventually landed in San Francisco.
He was designated for assignment twice this season but stuck with the Giants and has won each of his three starts since being called up late last month to make a case for a roster spot next season.
''Just a beautiful game,'' Bochy said. ''A tremendous display of pitching. He was pounding the strike zone all day with all his pitches. He's fought his way to get back up here. He was up here earlier and went back to Fresno. He's just done a tremendous job and he's trying to send a message that this is where he belongs and where he should be pitching.''
Petit, making his 40th career start, needed 65 pitches to get through seven innings. The right-hander went to a three-ball count twice and did not throw more than five pitches to any one batter through seven.
Pence singled and scored on an error by shortstop Chris Owings in the second. He doubled and scored on Hector Sanchez's base hit in the fourth. Pence then hit a drive to left in the eighth for San Francisco's first homer at home since Aug. 21.
Sanchez went 3 for 3 and also was behind the plate for Petit's best start of his career.
''We had a good plan,'' Petit said. ''We had good communication through the whole game.''
NOTES: Giants LHP Dan Runzler cleared waivers and was outrighted to Triple-A Fresno. ... Giants C Buster Posey missed his third straight game with a swollen right ring finger. He's expected to miss at least two more games. ... RHP Matt Cain (8-8, 4.43 ERA) will start Saturday night's game for the Giants. He's 14-6 in 31 starts against the Diamondbacks. ... RHP Brandon McCarthy (3-9, 4.94) gets the start Saturday for the Diamondbacks. He's coming off his eighth career complete game. ... The gametime temperature of 72 degrees made it the hottest night game of the season in San Francisco.