Medica singled after a 14-pitch at bat, with Guzman watching intently from the on-deck circle. Guzman then homered in a four-run fourth inning.
"I saw a lot of pitches and I hit it good," Guzman said. "He made the pitcher throw a lot of pitches and then he gets the hit."
Hunter Pence, who reached a tentative agreement on a $90 million, five-year contract before the game, hit a two-run homer for the Giants. San Francisco had won three in a row.
Eric Stults (11-13) pitched seven effective innings to win his third straight start after going 0-6 in his previous 10 starts. He also helped himself with an RBI single during a four-run fourth.
"I made some adjustments and was able to follow through on them," Stults said. "Every player wants to end on a good note and sometimes you have to battle the storm a little and keep pushing through."
Stults allowed three runs on seven hits. He did not walk a batter and struck out three.
Yusmeiro Petit (4-1) lasted a season-low 3 2/3 innings, giving up five runs and seven hits.
"I felt good all the way around," Petit said. "This is a learning experience for me because when I get into big trouble I have to find a way to get out of it."
Denorfia led off the game with his career-best 10th home run.
Angel Pagan doubled to open the bottom of the first and scored when Sandoval doubled with two outs.
Pence hit his 27th homer in the third to put the Giants ahead 3-1. His homer total is the highest for the Giants since Barry Bonds hit 28 in 2007.
Petit retired the first two batters in the fourth and then gave up six consecutive hits, including the long at bat by Medica, before being replaced by George Kontos.
"He was throwing everything," Medica said. "He kept making good pitches and I was fortunate to keep getting a piece of them until I finally got one fair."
Chase Headley doubled ahead of Medica. Guzman hit his homer and consecutive singles from Alexi Amarista, Chris Robinson, making his first major league start, and Stults produced another run and ended Petit's day.
Stults, who retired his last nine hitters, threw a career-high 203 2/3 innings this season.
"It's definitely a milestone," Stults said. "The goal was to make it through the season healthy and try to be reliable."
The Padres added four runs in the ninth on Gyorko's 22nd home run, a two-run shot, and RBI singles from Denorfia and Reymond Fuentes.
Gyorko has the most home runs by a rookie second baseman since Dan Uggla hit 27 for the Marlins in 2006.
Giants INF Brandon Belt will be working on his versatility during the offseason according to manager Bruce Bochy. ... RHP Guillermo Moscoso (2-2, 4.21) will start Sunday's season finale for the Giants. It's his first start since Aug. 4. ... RHP Tyson Ross (3-8, 3.10) makes the start for the Padres on Sunday. He has an ERA of 2.80 over his last 12 starts. ... Denorfia hit his second leadoff homer of the season and seventh of his career. ... Medica had his first career three-hit game.
The Angels say Shohei Ohtani's six-week re-evaluation revealed that his ulnar collateral ligament "continues to show improved healing."
The Oakland Athletics have released veteran reliever Santiago Casilla, five days after he was designated for assignment.
Cubs closer Brandon Morrow was placed on the DL with biceps inflammation.
As the second half begins, we examine what history tells us about division leaders' chances of holding on down the stretch.
Jerry Crasnick believes Cleveland is ready to win now so adding Brad Hand proves it is a legitimate World Series contender.
The AL Central leaders improved their bullpen for October and the years to come, but sent a potential star catcher to San Diego in the process.