PITTSBURGH -- A throwing error by pitcher Jared Hughes on a sacrifice bunt by reliever Jean Machi allowed the Giants to score the winning run in the 13th inning and overcome a six-run deficit to beat the Pittsburgh Pirates 11-10 Monday night.
Hughes (1-1) came on to start the 13th. With one out, he walked Hunter Pence and hit Juan Perez with a pitch. Machi (5-0), in just the second plate appearance of his four-year career, then dropped down a bunt, which Hughes fielded and threw wildly past first base as Pence scored from second base.
Giants backup catcher Hector Sanchez had four hits and three RBIs, while Buster Posey, who got a day off from catching, had three hits, three runs scored and two RBIs. Pence finished with three hits and scored four times and Angel Pagan also had three of San Francisco's 20 hits. Michael Morse drove in two runs with a pair of doubles.
Machi pitched two scoreless innings and Sergio Romo worked the 13th for his 10th save.
The Pirates' Andrew McCutchen had four hits and Pedro Alvarez homered and drove in four runs.
The Giants tied the score at 10-10 and forced extra innings on Posey's single in the ninth.
Both fill-in starters struggled as San Francisco's Yusmeiro Petit was racked for eight runs and nine hits in 4 1-3 innings and Pittsburgh's Jeff Locke, an All-Star last season, surrendered six runs and eight hits in 5 1-3 innings after being recalled from Triple-A Indianapolis earlier in the day.
Petit started in place of Matt Cain, who was placed on the disabled list Sunday with a cut on his right index finger. The Pirates needed a spot starter after their rotation was scrambled last week by back-to-back rainouts in Baltimore, so they called on Locke, who went 1-5 with a 6.66 ERA in his last 11 starts of 2013.
Pinch-hitter Jose Tabata put the Pirates ahead 10-9 with an RBI infield single in the seventh inning after they had squandered an 8-2 lead.
The Pirates went ahead by six runs after scoring four times in the fifth inning, but San Francisco went ahead 9-8 with five runs in the sixth and two in the seventh.
Brandon Hicks' two-run double highlighted the sixth inning that also included RBI singles by Posey and Angel Sanchez and Brandon Crawford's sacrifice fly that drew the Giants within 8-7.
Pittsburgh's Jordy Mercer doubled and scored on Neil Walker's groundout in the bottom of the sixth inning to give the Pirates a two-run cushion, but San Francisco tied it in the seventh when Morse doubled in a run and scored on a single by Posey.
Alvarez's booming three-run home run to center field, his eighth of the season, capped a four-run third inning that put the Pirates ahead 4-2. Walker drove in the first run with a single.
Alvarez then drove in the first run in a four-run fifth that put the Pirates ahead 8-2 with a bloop single. Two runs scored on wild pitches by reliever Jake Dunning, who joined the team Monday after being recalled from Triple-A Fresno on Sunday, and sacrifice fly by Clint Barmes.
The Giants scored twice in the first inning as Morse doubled in a run and scored on Sanchez's single.
NOTES: Giants manager Bruce Bochy is confident Cain will make his next scheduled start Saturday against the Dodgers at Los Angeles. Cain was originally supposed to pitch Monday, but was placed on the disabled list, retroactive to April 24, on Sunday with the cut on his right index finger. . San Francisco 1B Brandon Belt, who entered the game in a 2-for-29 slump, got the night off. . Pittsburgh RHP Jason Grilli played catch for the second time in three days but there is no timetable for when the closer, who is on the DL with a strained left oblique, will be able to throw off a mound. . The Pirates optioned RHP Casey Sadler to Indianapolis to open a roster spot for Locke.