SAN FRANCISCO (AP) -- Cody Asche took one look at the starting lineup and felt his confidence grow. Phillies manager Ryne Sandberg challenged him, and that was enough.
Asche hit a two-run homer in the eighth inning to tie the game and then started the decisive rally with a double to open the 10th as Philadelphia rallied to beat the San Francisco Giants 5-3 on Friday night.
''He saw something in me that made him want to put me in,'' Asche said. ''I was confident just by the fact I was in there.''
Chase Utley was hit by a pitch with the bases loaded in the 10th and Ryan Howard followed with a sacrifice fly against Javier Lopez, snapping the Phillies' three-game losing streak.
Sandberg gave Andres Blanco the day off and went with Asche against Madison Bumgarner.
''If you want a chance to become a regular player, you have to face lefties,'' Sandberg said.
Asche connected against Jeremy Affeldt, who allowed his first home run this season, and doubled off Santiago Casilla (1-3) to set the stage for the winning rally.
Ken Giles (2-0) pitched two scoreless innings, and Jonathan Papelbon worked the 10th for his 28th save in 31 chances.
Bumgarner threw seven strong innings for his first quality start at home since June 10, a span of seven games. He allowed one run and four hits, striking out nine without a walk.
''It was nice to pitch a good game at home,'' Bumgarner said. ''It's been forever.''
Cole Hamels also delivered a quality start for Philadelphia, giving up three runs and nine hits over seven innings. He walked two and struck out five.
Pablo Sandoval had three hits, but the Giants lost their sixth in seven games.
Bumgarner retired the first 10 hitters he faced, five on strikeouts, before allowing back-to-back hits by Jimmy Rollins and Utley.
Hamels let the leadoff hitter reach base in five innings and had baserunners every inning. He was able to avoid trouble with the exception of the fourth.
Buster Posey led off with a single and Sandoval hit a ground-rule double ahead of Michael Morse's first home run in August, a three-run drive into the left-field seats.
Marlon Byrd countered with his 23rd homer leading off the fifth.
Phillies: OF John Mayberry Jr. continues to deal with inflammation in his left wrist. His recovery has been interrupted by minor setbacks following workouts.
Giants: 1B Brandon Belt will get another opinion on his concussion when the Giants visit Chicago next week. Belt will see concussion specialist Michael Collins in Pittsburgh.
Phillies: RHP Kyle Kendrick (5-11, 4.88 ERA) takes the mound Saturday afternoon. He is 1-3 in his past six starts and has an ERA of 6.98 over his last seven.
Giants: RHP Tim Hudson (8-9, 2.81) pitches Saturday. The Giants have lost seven of his last 10 starts. Hudson has started 30 games against the Phillies and is 11-10 with a 3.60 ERA against them.
BYRD IS THE WORD
Giants third base coach Tim Flannery sent Sandoval home with two outs in the eighth on Joe Panik's single to right. Byrd's throw to Carlos Ruiz was there in plenty of time, keeping the game tied.
''Defense always comes first,'' Byrd said. ''I'm not always going to hit, and I take pride in my defense.''
Byrd also ran down Morse's 400-foot fly in the second to the roomy area of the ballpark known as Triples Alley.
COOL LIKE CARLTON
Hamels had his streak of pitching at least seven innings and allowing no more than one earned run stopped at five games, one shy of matching the franchise record. Steve Carlton was the last Phillies pitcher to do it, in 1972. Grover Cleveland Alexander (1916) and Elmer Jacobs (1918) also accomplished the feat.