Updated

Madison Bumgarner threw seven strong innings and drove in a pair of runs to help the San Francisco Giants take a 4-2 win over the Los Angeles Dodgers in the second of a three-game set.

Bumgarner (9-5), who was named to the All-Star Game earlier on Saturday, won for the fifth time in his past six starts as he gave up just two runs on three hits with nine strikeouts for the Giants, who came into the game having dropped 10 of their previous 11 games. Gregor Blanco went 3-for-3 with an RBI in the win.

"It's a huge honor," Bumgarner said of being named to the All-Star Game. "Definitely excited and just blessed to be a part of it."

Tim Federowicz hit a two-run home run for the Dodgers, who had won five of six prior to the setback. Stephen Fife (3-3) was charged with four runs -- one earned -- on seven hits in 4 1/3 innings.

"I feel like I've put my best foot forward and hopefully that's good enough," Fife said when asked if he thought he would remain in the rotation.

Los Angeles had some good news on Saturday, though, as the team acquired pitcher Ricky Nolasco and a fourth-round selection in the 2013 International Bonus Pool from the Miami Marlins in exchange for pitchers Steven Ames, Angel Sanchez and Josh Wall.

The Giants nearly got a run in the first as Buster Posey hit a pitch into right field, scoring Blanco. However, Posey batted out of order as it was Pablo Sandoval's turn at the plate. The umpires ruled Sandoval out, and Posey flied out on his at-bat to end the inning.

In the second, though, the Giants did go on top with three runs. With the bases loaded and one out, Bumgarner worked a walk to force in the first run and Blanco then beat out an infield single for another run. Marco Scutaro then hit a sacrifice fly to plate Brandon Crawford for a 3-0 lead.

San Francisco got another run across in the fourth as Andres Torres reached second base on an error from Hanley Ramirez, moved to third on Crawford's fly out, then scored when Bumgarner followed with a sacrifice fly for a 4-0 lead.

Bumgarner was cruising through the game by retiring the first 14 batters he faced, but Andre Ethier broke the string with a two-out single to left in the fifth. Federowicz followed with his third home run of the season to make it a 4-2 game.

Ramirez tripled with one out in the seventh and Juan Uribe followed with a grounder to third. Sandoval went home with the ball and Posey tagged out Ramirez to keep it a two-run game.

In the eighth, Sandy Rosario came on to relieve Bumgarner and got the first out, but then allowed a pinch-hit double from Jerry Hairston. Mark Ellis then grounded out and Javier Lopez came on to strike out Carl Crawford to end the inning.

Sergio Romo put the Dodgers down in order in the ninth to pick up his 20th save of the season.

Game Notes

The Giants have taken six of the 11 games against the Dodgers this season ... Los Angeles went 0-for-3 with runners in scoring position and left two on base, while the Giants were 1-for-10 with RISP and left seven ... Los Angeles pitcher Clayton Kershaw was named to the All-Star game on Saturday, while the Giants will be sending Posey and Scutaro in addition to Bumgarner.