Nationals 6, Giants 5: Rookie Bryce Harper singled home the tying run in the bottom of the ninth and scored the winning run on Adam LaRoche's groundout as host Washington rallied to complete a three-game sweep of San Francisco.
Ian Desmond and Danny Espinosa clubbed back-to-back solo homers in a three-run seventh as the Nationals extended their winning streak to four games.
Harper also doubled in a run in the seventh for Washington, which erased a 5-1 deficit and moved a season-high 16 games above .500.
Tyler Clippard (2-2) pitched a perfect ninth to help the Nationals post their first three-game home sweep of San Francisco since July 2006.
Giants closer Santiago Casilla (2-4) gave up a leadoff pinch-hit double to Tyler Moore before bobbling a sacrifice bunt by Steve Lombardozzi to bring up Harper, who singled to right to tie it at 5-5.
After a force-out at the plate, LaRoche grounded to second base, but the Giants were unable to turn the double play as Harper crossed the plate with the winning run.
Melky Cabrera had two hits and three RBIs and Angel Pagan added three hits and two RBIs for the Giants, who have lost five of six.
Matt Cain allowed three runs on six hits in 6 2/3 innings for San Francisco. Nationals starter Ross Detwiler yielded three runs on 11 hits in five innings.
GAME NOTEBOOK: Desmond extended his hitting streak to 10 games. He has 12 RBIs during the stretch. ... Giants 2B Freddy Sanchez underwent season-ending back surgery Thursday. Sanchez, who has not played since June 10, 2011, will have part of a disk removed from his back. The three-time All-Star will be a free agent after the season. ... Harper finished third in the Final Vote contest to determine the last slot on the NL All-Star team. St. Louis' David Freese won the vote and Atlanta's Michael Bourne was second. ... The teams wore throwback uniforms on Turn Back the Clock night to honor their respective 1924 squads.