PHOENIX -- It took a Giant village to beat Zack Greinke, but San Francisco got it done.
Joe Panik homered, Johnny Cueto won his fifth game and Javier Lopez induced a game-ending groundout with the bases loaded in the Giants' 4-2 victory over the Arizona Diamondbacks at Chase Field on Thursday, their first victory over nemesis Greinke in 12 career meetings.
"Finally broke through," Giants manager Bruce Bochy said. "He's been tough on us. We had some good at-bats. Panik, that was huge to give us a little cushion. It got a little scary at the end, but 'Lopey' got the big out there."
Panik's two-run homer on a first-pitch fastball gave Cueto a 4-1 lead in the fifth inning, and Lopez got Jake Lamb to ground out in the ninth inning to preserve the victory with his first save of the season.
"Any time against (Greinke), you are looking for a certain area," Panik said. "I wasn't say I was guessing heater, it was more look for something up in zone."
Greinke had been 8-0 with a 2.12 ERA against San Francisco, all the victories since 2014.
"He's a heck of a pitcher," Lopez said. "He's a heck of a competitor. That's obviously why we made a big push for him in the offseason. If you can't beat 'em, join 'em kind of thing. It's great to get that, especially when you are starting a road trip."
The Giants (19-18) had eight hits off Greinke, the most they had against him in one game, to help Cueto (5-1) win the first matchup between the two big offseason free agent pitching signees.
Greinke (3-3) signed a six-year, $206.5 million contract this winter, and Cueto signed a six-year deal worth $130 million. Each organization negotiated with the other pitcher before the deals were done.
Cueto gave up two runs and eight hits in seven innings to lower his ERA to 2.97. He struck out nine and walked two.
"I let the batters take care of the pitcher," Cueto said when asked about the matchup with Greinke.
Greinke gave up four runs and eight hits in six innings. He struck out four and walked three. Greinke has a 7.28 in five starts at Chase Field while giving up six homers.
"It was all right, not great," Greinke said of his outing. "They had some really good at-bats. Took a lot of close pitches and were ready to hit any time I made a mistake."
"They did have some good swings against him, put together some good at-bats," Arizona manager Chip Hale said. "He gave us six innings.
"Four runs in our ballpark, I think we should be able to counter that."
Jean Segura had three hits and Brandon Drury had two for Arizona (17-20), which lost its second in a row after a five-game winning streak.
Three of the first four Diamondbacks batters singled off Cueto in the first inning, and cleanup hitter Lamb drove in Segura for a 1-0 lead.
The Giants bunched four singles to take a 2-1 lead in the fourth inning. Matt Duffy, Posey and Brandon Belt singled to open the inning, with Belt driving in a run. Hunter Pence beat out a potential double-play grounder to drive in Posey.
Span singled and Panik hit his fourth homer of the season to lead off the fifth inning, making it 4-1 lead. Span had two singles off Greinke and is 13-for-40 against Greinke in his career.
Chris Owings tripled in a run to make it 4-2 in the sixth.
NOTES: Arizona RF David Peralta (right wrist) missed his fifth consecutive start. An MRI exam Thursday showed no structural damage and there is "nothing to be concerned about," general manager Dave Stewart said. ... The Giants added RHP Clayton Blackburn to the roster Thursday, giving them 13 pitchers for the four-game series at Arizona that began Thursday. The Giants optioned OF Jarrett Parker to Sacramento to make room for Blackburn, an indication that OF Angel Pagan (hamstring) is close to returning. Pagan has missed 10 straight games but did pregame work Thursday and is likely to start Friday, manager Bruce Bochy said. ... Arizona general manager Dave Stewart, on a possible pursuit of former Giants RHP Tim Lincecum: "We don't have any plans at this point." The D-backs were among numerous teams that attended Lincecum's throwing session in Scottsdale last Friday. ... The street on the west side of Chase Field was renamed "Randy Johnson Way" in a ceremony Thursday, and Johnson threw out the first pitch. ... RHP Zack Greinke doubled in the second inning, his 17th double in 309 career at-bats.