PHILADELPHIA (AP) -- The struggling Giants couldn't add to their lead and it cost them.
Maikel Franco drove home the winning run with one out in the 12th inning on a play that eventually was ruled a single, giving the Philadelphia Phillies a 5-4 victory over San Francisco on Wednesday night.
Buster Posey singled, doubled and drove in three runs for the NL West leaders, who have lost 13 of 17 since the All-Star break. Denard Span had three hits.
More from FoxSports
The Giants blew a 4-0 lead and managed just two hits against six Philadelphia relievers, who combined for seven shutout innings.
"We couldn't tack on, we couldn't do anything with their bullpen, we couldn't get anybody on," San Francisco manager Bruce Bochy said. "That was difference in the game. Their `pen shut us down completely."
Giants starter Johnny Cueto was cruising along until giving up consecutive solo homers in the seventh and Franco's two-run single that tied it in the eighth. He was lifted after allowing four runs in 7 2/3 innings while recording his 12th career double-digit strikeout game by fanning 10 Phillies. The right-hander gave up seven hits and walked one.
"I felt normal," Cueto said through a translator. "I made all my pitches. The only thing I can say is they beat me."
Cueto said the Giants have to play their way out of their slump.
"It's hard to believe," he said. "We're a good team. The only thing we can do is keep grinding and keep putting our best effort out there, every time we go out."
Cueto's night was long over when the game ended in strange fashion.
With the bases loaded and one out in the 12th, Franco lined what appeared to be a clean single into right-center field. But young teammate Aaron Altherr, who was on first base, got so excited about the Phillies winning that he rushed out to right field to congratulate Franco without ever touching second base.
Posey, the Giants' catcher, noticed the blunder and took a throw at second from right fielder Hunter Pence -- and second base umpire Dale Scott signaled that Altherr was out. Franco did indeed cross first base, though, so Tommy Joseph scored easily from third and the Giants had no chance at an inning-ending double play.
"When I saw (Hunter) Pence run out to center field to get the ball, I was like, `What's going on here?'" Altherr said. "Then when I saw him throw to second I was like, `Oh, (no).' I feel terrible about it. I'm just thankful we still got the win."
Altherr said he would buy Franco dinner if the mistake cost his teammate a hit, but after a long delay following the game, the official scorer credited Franco with a single.
"It's more important that we won the ballgame," Franco said before the ruling. "I got my RBI, we win the ballgame, that's what this game is all about."
Ryan Howard homered among his three hits and Cameron Rupp also connected for Philadelphia. Franco finished with three RBIs.
George Kontos (2-2) started the 12th by hitting Joseph with a pitch. He went to second on Luis Garcia's sacrifice bunt and Philadelphia had runners on first and second with one out after Kontos walked Cesar Hernandez.
Bochy called on Jake Peavy for his first appearance since being demoted to the bullpen when the team acquired left-hander Matt Moore from Tampa Bay on Monday.
Peavy induced a grounder by Altherr, but he reached to load the bases when third baseman Eduardo Nunez bobbled the ball for an error.
Franco drove the next pitch from Peavy into right-center.
"Anytime you win in extra innings, it's a great win," Phillies manager Pete Mackanin said. "When you lose, it's terrible."
Garcia (1-0) pitched a scoreless inning, capping an impressive performance by Philadelphia's bullpen.
The teams combined to use 14 pitchers in a game that took 4 hours, 2 minutes.
Phil Klein recovered from a shaky first inning in an emergency start for the Phillies and lasted five innings, giving up four runs and eight hits. Philadelphia scratched scheduled starter Aaron Nola 4 hours before the game and placed him on the 15-day DL with a strained elbow.
Prior to Wednesday, Klein made eight relief appearances for Texas this season and had pitched 36 games in his big league career. He was a 30th-round selection by the Rangers in 2011.
Klein was optioned back to Triple-A following the game.
The teams conclude their three-game series Thursday afternoon when Phillies RHP Vince Velasquez (8-3, 3.32 ERA) opposes Moore (7-7, 4.08).