SAN FRANCISCO -- A 28-year-old journeyman pitcher who was designated for assignment twice by the Giants this year came within one strike and a few feet from perhaps the most unlikely perfect game in baseball history Friday night at AT&T Park.

Yusmeiro Petit, making just his third start for the Giants this season and the 40th in an up-and-down major league career, recorded 26 consecutive outs and had a 3-2 count against Arizona Diamondbacks pinch-hitter Eric Chavez with two outs in the ninth inning. But Chavez lined a single to right field that just eluded the diving try of outfielder Hunter Pence.

Petit quickly regrouped to record the last out and settled for a one-hitter, his first major league complete game and shutout. He needed just 95 pitches -- 69 of them strikes -- to throw the game of his life in a 3-0 Giants victory, and at least he seemed satisfied with that. But his team was taking it harder.

Pence, for one, was still replaying the Chavez single in his mind.

"It felt like when it was hit it was one of those dreams where you can't run fast enough," said Pence, who saved Tim Lincecum's no-hitter earlier in the year with a diving catch. "Off the bat, it was just a little too far. But I gave it my best effort, and I was just a little bit shy."

Petit said he told himself that when the count got to 3-2, he had to come up with just the right pitch, and he thought he'd thrown it -- a fastball low and outside. But Chavez somehow turned on it and flipped it into the outfield.

"A lot of credit to Chavez, good at-bat," catcher Hector Sanchez said. "He took a lot of good pitches down in the zone. Finally, on 3-2, (Yusmeiro) threw a really good pitch on the outside corner, but Chavez hit it really good."

"Usually when you try to pull a pitch like that you roll it over and ground out," said Pence.

Petit also threw a tantalizing pitch on 2-2 -- a curveball just on the outside edge -- that Chavez laid off.

"I didn't think it was a strike," the pitcher said through interpreter Jose Alguacil, the Giants' roving infield instructor. "But I was surprised that he didn't swing at that."

A standing, delirious crowd of 41,180 groaned as Chavez's liner bounced just in front of Pence but just as quickly regrouped and roared its approval of Petit's performance. After the last out, the Giants excitedly poured out of the dugout to congratulate the Venezuelan right-hander, who might have cemented a spot on the team's 2014 staff with this effort.

"You get that close, it breaks your heart a little bit," manager Bruce Bochy said. "But what impressed me was after he gave up the hit. You can have the tendency to let down a little bit, but he came right back and got that last out. That shows you his makeup -- he didn't let it bother him."

Said Arizona manager Kirk Gibson: "My thought is he's pitched a great game, now let's break his heart."

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."

Petit (3-0) became the 12th pitcher to lose a perfect game with two outs in the ninth inning and the second this season (Texas' Yu Darvish was the other).

It was nearly the second perfect game for the Giants in two years, following Matt Cain's 2012 perfecto. The remarkable part of that is that the forearm injury Cain suffered two weeks ago provided the opportunity for Petit to join the Giants rotation.

He might just stay there for the long term.

"He's kind of sent a message this is where he belongs and this is where he should be pitching," Bochy said.

Petit went to only two three-ball counts, once in the eighth and then again in the ninth against Chavez -- and struck out seven.

There wasn't even a threat of a hit through the first five innings against Petit. In the sixth, Bochy made a key strategic move, replacing starting left fielder Brett Pill with Juan Perez for defense, and after Petit got the first two outs on easy grounders, Perez preserved the perfect game with a diving grab of opposing pitcher Patrick Corbin's sinking liner to left.

Perez said he wasn't nervous whatsoever as Petit got closer and closer to the perfect game.

"I was hoping to get a chance to make another catch," he said.

The Giants staked Petit to a 1-0 lead in the second with the help of an Arizona error and made it 2-0 in the fourth on a Pence double and two-out RBI single to center by Sanchez. Pence hit his 19th home run, a solo shot in the eighth, to give Petit even more cushion.

  • Buster Posey said his fractured right ring finger was feeling much better, that the swelling had gone down and that he was planning to hit off a tee. Bochy said it would likely take a few more days until Posey is ready to play.

  • Left-handed reliever Jeremy Affeldt threw his second session to live hitters in batting practice, and Bochy was less than enthusiastic about what he saw. "I don't think he's quite ready," he said. Affeldt is on the disabled list with a strained groin.

    The Associated Press contributed to this report.

    SATURDAY'S GAME

    Arizona (Brandon McCarthy 3-9)
    at Giants (Matt Cain 8-8),
    6:05 p.m. CSNBA

    Online extra

    Scan this code with a smartphone to view a Giants photo gallery or go to http://photos.mercurynews.com.


    The Diamondbacks' Paul Goldschmidt flips his bat after becoming one of Yusmeiro Petit's seven strikeout victims.


    Eric Risberg/Associated press photos

    Yusmeiro Petit didn't allow an Arizona base runner until Arizona pinch-hitter Eric Chavez singled with two outs in the ninth inning.