Updated

Joaquin Arias stroked a solo home run among his three hits and knocked in three as the San Francisco Giants beat the San Diego Padres, 8-7, in the second installment of a three-game series Saturday at Petco Park.

Buster Posey clubbed three hits, scored twice and also knocked in a run for the Giants, who won for the fifth time in their last seven games.

Jose Mijares (1-0) earned the victory after recording the final out of the sixth and retiring the first batter of the seventh.

Chase Headley belted a three-run homer and Carlos Quentin added a solo shot in the setback, San Diego's fifth in a row.

With the game tied at 5-5, Brad Brach (1-3) surrendered a pair of runs in the seventh to absorb the loss.

Marco Scutaro singled to start the frame, went first-to-third on a base hit by Pablo Sandoval, and then scored on Posey's sacrifice fly to right field.

After Hunter Pence walked, Arias smacked a single through the right side of the infield to score Sandoval for a 7-5 advantage.

The Giants tacked on an insurance run in the ninth as Posey doubled before Pence followed with a two-bagger of his own to make it a three-run game.

"Good win for us, good comeback," said Giants manager Bruce Bochy. "The guys did a great job of having another big inning to save us."

The bullpen held San Diego down from there until Jeremy Affeldt surrendered a pair of runs in the ninth.

The lefty retired the first two hitters, but walked pinch-hitter Yonder Alonso before Alexi Amarista singled home Alonso. Amarista moved to second on a fielder's indifference and then scored on Chris Denorfia's base hit to right field.

Clay Hensley entered for Affeldt and fanned pinch-hitter Mark Kotsay to nail down his third save of the season and maintain the Giant's 1/2 game lead in the NL West over the Dodgers, who were also victorious on Saturday.

"We don't give up. We play hard for 27 outs," Headley said. "We gave them a game there at the end."

Arias' leadoff blast in the second inning gave the Giants a 1-0 lead before the Padres loaded the bases with no outs in the bottom half.

They'd settle for just one run, however, as Cameron Maybin's fielder's choice ground out plated Quentin before Maybin was caught stealing and Everth Cabrera fanned.

San Diego jumped in front in the third as Padres starter Eric Stults and Logan Forsythe each singled before Headley launched his 20th homer of the season into left field to give the home team a 4-1 lead.

The Giants battled back in the fifth as pinch-hitter Ryan Theriot singled, Angel Pagan doubled and Scutaro smacked a sac fly to plate Theriot.

Sandoval followed with a fielder's choice to score Pagan, before Posey doubled to put runners on second and third with one out.

Pence then lifted a sac fly to center field and Arias plated Posey with a line-drive single to left field for a 5-4 lead, but Quentin's leadoff homer to left field in the sixth tied the game at 5-5.

Game Notes

San Francisco starter Barry Zito allowed four runs on six hits and two walks over four innings ... Stults was charged for five runs on nine hits over six frames ... The Padres recalled pitcher Nick Vincent from Triple-A Tucson and optioned right-hander Ross Ohlendorf to Tucson ... Headley has hit eight home runs and has 24 RBI in 14 games so far in August.