Updated

Ryan Zimmerman hit a two-run blast and drove in three as Washington launched four home runs en route to a 9-4 victory over San Francisco in the middle test of a three-game set.

"It's hard to shuffle the lineup around and have guys hit in different spots all year," Zimmerman said of the NL East leaders. "Now that we're trying to get healthy, guys are able to find out what they can do and finally get comfortable."

Ian Desmond drove in a pair, while Rick Ankiel, Michael Morse and Jhonatan Solano also went deep for the Nationals, who have won three in a row and six of their last eight.

Edwin Jackson (5-4) allowed five hits and four runs over 5 2/3 innings for the win.

Pablo Sandoval finished 3-for-4 and knocked in three runs -- two of those on a homer -- for the Giants, losers in four of their last five.

Madison Bumgarner (10-5) was rocked for seven runs and nine hits despite fanning seven over five-plus frames.

The Nats took the lead for good, going up 4-3 in the fourth on Solano's one- out solo shot, then moved ahead by a 7-3 count in the fifth. Bryce Harper began the inning with a single, then scored on Zimmerman's two-run homer. That was followed by a Morse blast for the four-run margin.

Sandoval drove in Emmanuel Burriss with a double in the sixth, but in the home eighth Roger Bernadina singled ahead of a two-run homer from Ankiel. Zimmerman had the chance to add to his big afternoon, up with the bases loaded and one out, but hit into an inning-ending double play.

Mike Gonzalez turned in a scoreless ninth to lock up the victory.

The Giants picked up three in the first. Gregor Blanco worked a leadoff walk and moved to third on a one-out single from Melky Cabrera. He eventually came in on a Buster Posey groundout, then Sandoval launched a two-run shot to center.

Washington knotted the score in the third as Zimmerman doubled in a run and Desmond singled home a pair with two outs.

"We did what we wanted, put up a crooked number early on," said Giants manager Bruce Bochy. "But you could tell, he was toughing it out in the heat, and eventually it got to him."

Game Notes

Zimmerman's homer was his fourth career longball on Independence Day, tying him with Torii Hunter for the most on America's birthday since 2006...Washington's bullpen of Tom Gorzelanny, Sean Burnett and Gonzalez held San Francisco to a pair of hits over the final 3 1/3 innings...Washington improved to 5-3 on July 4 since the franchise relocated from Montreal.