McCutchen and Longoria each had two hits and an RBI for San Francisco. Posey and Austin Jackson also drove in runs.
The Giants improved to 6-2 on their 10-game homestand.
San Diego scored three times off reliever Reyes Moronta in the sixth to take the lead but stranded runners in scoring position in the seventh and eighth and left a man on first in the ninth.
Franchy Cordero had two hits and walked twice. Eric Hosmer also had two hits and Chase Headley added a pinch-hit RBI single for the struggling Padres.
The Giants’ rally prevented Padres rookie Eric Lauer from getting his first major league win. The 22-year-old struck out six in five innings and pitched through traffic most of the night but left after San Diego took a 5-3 lead.
Padres: Starting catcher Austin Hedges was removed in the bottom of the second with right elbow tendinitis. Hedges struck out in the top half and was replaced by A.J. Ellis.
Giants: Hoping for clearance to begin a throwing program, San Francisco ace Madison Bumgarner traveled to Arizona to meet with the same doctor who performed surgery on his left pinkie. Dr. Donald Sheridan inserted three pins into Bumgarner’s pinkie after the 2014 World Series MVP was hit by a line drive late in spring training. . 2B Joe Panik underwent surgery on the ulnar collateral ligament in his left thumb and will miss at least six weeks. . OF Mac Williamson remains in concussion protocol.
RHP Tyson Ross (2-2, 3.64 ERA) pitches for the Padres on Tuesday in his fourth road start of the season. LHP Andrew Suarez (0-1, 6.75) is scheduled to start for the Giants.