Updated

SAN DIEGO (AP) -- Brandon Belt hit a tying solo home run in the sixth inning and Buster Posey hit a go-ahead, two-run double in the seventh to lead the San Francisco Giants to a 7-1 victory over the San Diego Padres on Wednesday.

Matt Cain pitched six strong innings in his fourth start of the season for the defending World Series champions, who took two of three and have won eight of nine overall.

Padres ace James Shields left with a 1-0 lead after throwing 96 pitches in five innings, and the bullpen promptly gave up the lead.

Belt homered into the sandy play area beyond the fence in right-center on a 3-2 pitch from Marcus Mateo with two outs in the sixth. It was Belt's 10th.

Brandon Maurer (6-3) came on for the seventh and allowed Angel Pagan's one-out single before getting Joe Panik to ground to first. He walked Matt Duffy, who checked his swing on a 3-2 pitch, before Posey doubled to right, with the ball landing just in front of a diving Matt Kemp to give the Giants a 3-1 lead. Hunter Pence singled to right-center to bring in Posey.

The Giants piled on with three more runs against Dale Thayer in the eighth. Brandon Crawford hit a leadoff homer into the Jack Daniels' party deck atop the right field wall, his 14th. Justin Maxwell had a pinch-hit RBI single and Duffy had an RBI base hit.

Cain (2-1) allowed one run and five hits in six innings, with six strikeouts and one walk. He was making his fourth start of the season. He had elbow surgery in 2014 and had been sidelined this season with a strained flexor tendon.

Shields, coming off his first victory since June 3, held the Giants to three hits in five scoreless innings while striking out seven and walking three.

Jedd Gyorko homered off Cain leading off the second inning, his fifth.

TRAINER'S ROOM

Giants: LHP Jeremy Affeldt, sidelined since June 16 with a strained left shoulder, was activated from the 15-day DL. He faced two batters in the eighth, allowing a single and a walk. To make room, LHP Josh Osich was optioned to Triple-A Sacramento.

UP NEXT

Giants: RHP Jake Peavy (1-4, 4.94 ERA) is scheduled to start when San Francisco opens a three-game home series against Oakland. The A's will counter with RHP Jesse Chavez (5-9, 3.21).

Padres: RHP Tyson Ross (6-7, 3.38) is scheduled to start the opener of a four-game series against Miami. The Marlins counter with RHP Tom Koehler (7-6, 3.38).