The Pirates had a six-run lead after five innings, a perfect combination to unlock the safe housing the first victory by their starter since April 17.
Locke did not get a win. And neither did the Pirates, as the Giants validated a furious comeback by turning pitcher Jean Machi's sacrifice bunt into a 13th-inning unearned run and an 11-10 victory.
This was the Bucs' first game to see both teams score in double figures since July 12, 2008, when the Pirates edged the Cardinals here, 12-11, in 10 innings.
"It was a night we gave it everything we had, and came up one run short at the end," said Pirates manager Clint Hurdle, who didn't seem to be as shell-shocked as he could have been following a five-hour, 29-minute game lost in uncharacteristic fashion.
Locke was given a hook 65 pitches into the game, five batters into a sixth inning he had begun with an 8-2 lead and having retired 13 straight.
However, he had the National League's fourth-best (by ERA) bullpen behind him. Not on this night; even with Tony Watson and Jeanmar Gomez doing shutout work, all told, six relievers gave up five runs and 12 hits in 7 2/3 innings.
Jared Hughes was the last of those relievers. He issued a one-out walk to Hunter Pence and nicked Juan Perez with a pitch to bring up Machi. Hughes picked up Machi's bunt a few feet in front of the plate and his throw to first skipped by Ike Davis as Pence motored home from second.
"I think the pitcher was a little bit slow reacting to go get the ball," Machi said. "When I saw that I used all the speed that I had and I think we got there almost at the same time, the ball and me."
Witnesses did double-takes upon seeing the 6-foot tall Machi haul his 255 pounds down the line like a lightweight speedster. The surprising speed might have rushed Hughes into the errant throw ... except he was not surprised.
"I played with Machi, in 2009 in Altoona," Hughes said of the former Pirates farmhand, who signed with the Giants as a Minor League free agent prior to the 2011 season. "And he was one of the fastest pitchers on that staff, so I knew he could run. And a good throw still would've had him."
Jose Tabata's tie-breaking RBI infield single in the seventh put the Bucs up, 10-9, but that lead didn't last longer than any of the others, the Giants making it 10-10 in the ninth on Buster Posey's run-scoring single off Mark Melancon.
The Giants made a game of it with a five-run retort in the sixth. Locke was working on his 13-out streak when Angel Pagan led off with a single. The barn door was open. Locke got one more out -- a strikeout of Michael Morse between RBI singles by Posey and Hector Sanchez -- and was gone.
"I thought he did a very commendable, professional job," Hurdle said of Locke, who had been recalled for this one spot start from Triple-A Indianapolis. "They chipped him [for two runs] in the first, then he had four very clean innings. Then the ball kinda got up on him a little bit. But he gave us a nice effort."
Bryan Morris relieved, and three more runs scored under his watch, two on Brandon Hicks' double and another on Brandon Crawford's sacrifice fly.
"They basically got to our location," Hurdle said, referring to both the location of pitches and struck balls. "We were up in the [strike] zone more than normal. And in that sixth inning, all I saw was [Starling] Marte running down balls in left field, and [Neil] Walker diving for three or four balls at second, and couldn't come up with anything."
Jordy Mercer doubled in the bottom of the inning and eventually came in on Walker's grounder to build the lead back to two runs -- wiped out in the seventh on run-scoring knocks off Watson by Morse and Sanchez.
Locke didn't wow witnesses, but he was downright supreme when it most mattered, after the Giants had grabbed a quick 2-0 lead and before the Pirates could answer loudly. The lefty retired those 13 consecutive batters from the first through the fifth.
"It's easy to let those innings pile up," Locke said. "I pride myself in the way I pitched after that first inning. There were times last year when I'd let that snowball. Today, I put my foot down."
First thing Locke did was fall right in line with the Bucs' 2014 staff when it comes to derailing baserunners. Pagan led off the game with a single -- and minutes later was caught stealing as Locke caught him off first base. Still, the Giants had some two-out lightning in them: Posey's single led to Morse's RBI double and Sanchez's run-scoring single for a 2-0 lead.
Pedro Alvarez did not let Locke wallow in that hole too long. The Bucs had already put one third-inning dent into San Francisco starter Yusmeiro Petit on Walker's RBI single when Alvarez came up with two on. The 3-0 pitch to him appeared six inches off the ground, and he started toward first base, only to be called back by home-plate umpire Phil Cuzzi.
Alvarez quickly got over that: He deposited Petit's next pitch into the Pirates' bullpen, the three-run shot giving him eight homers and 21 RBIs, and Locke a 4-2 lead.
Hearing the shutdown-inning call, Locke stood tall. He went through the Giants on six pitches the next inning, and after another breezy nine-pitch inning was in position for the win.
It marked only the 11th time in 32 games that the Pirates held a lead after the fifth inning -- a prime requisite for the starting pitcher to be able to get the win.
Neither Alvarez nor the rest of his band of Pirates were finished. An RBI single in the fifth gave Alvarez a four-RBI night. Later in that inning a pair of run-scoring wild pitches by Jake Dunning and sacrifice fly by Clint Barmes built an 8-2 lead.