SAN FRANCISCO - Matt Williams had his choice of arms to stop the Giants.

As the seventh inning spun out of control Tuesday night, with the National League Division Series hanging in the balance, the Nationals' rookie manager could have tapped his brilliant reliever Tyler Clippard. He could have also leaned on Stephen Strasburg, who was available in relief with the Nationals on the brink of elimination.

Williams chose Aaron Barrett, the 26-year-old rookie, whose meltdown sent the Giants to a date with the Cardinals in the NLCS.

In the space of three pitches, Barrett bounced a fastball to the screen, then threw another to the screen on an intentional walk. The wild pitch scored Joe Panik, pushing the Giants to a tense 3-2 victory to capture the series in four games.

The Nationals won 96 games, most in the league. For the second time in three years, their season stalled in the first round.

The Giants' Hunter Pence made a leaping grab against the wall to blunt a rally in the sixth inning, bouncing off the fence like a crash test dummy to end a rally. The Nationals' Bryce Harper followed in the seventh with a tying homer that sailed over the rightfield foul pole and into McCovey Cove.

Either image would have been a fitting representative for such a tense contest. Instead, the defining moment involved Barrett, who flailed when called upon to end a rally.

With runners on first and second, Barrett walked Pence to load the bases. With Pablo Sandoval at bat, Barrett bounced a wild pitch past Wilson Ramos. Panik scored from third and the Giants pushed ahead for good.

Barrett added to the misery. Williams signaled for an intentional walk of Sandoval. The pitch sailed over Ramos' mitt, one-hopping the screen. Ramos scrambled to retrieve it. He fired to the plate, where Barrett applied the tag in time to get Buster Posey.

The Nationals held the deficit to one. It didn't matter. The Giants had pushed ahead, and they weren't looking back.

In need of a near-perfect performance to force the series back to Washington, the Nationals made too many mistakes. They botched a pair of routine plays in the second inning, costly mistakes that led to a 2-0 deficit. Brandon Crawford's one-out single was the only ball to leave the infield.

But pitcher Gio Gonzalez failed to field a comebacker. Later, he botched the coverage on a bunt. Gonzalez walked Gregor Blanco to force in a run. Panik followed with a groundout to score Juan Perez.

To survive, the Nationals needed a flatlining offense to rediscover its pulse. The faintest beat did not register until the fifth, when Ryan Vogelsong was lucky to escape with the Giants leading 2-1.

Ian Desmond singled ahead of Harper, who scorched a cutter down the leftfield line. Desmond scored from first and Harper unleashed a fist pump when he pulled into second base.

Harper tied it in the seventh with one swing.

For the second time in the series, he hit a tape-measure shot off fireballer Hunter Strickland, whose 97-mph fastball wound up buzzing a few kayakers in McCovey Cove. Harper raised his right arm and stared down Strickland on his way around the bases.

His dugout greeted him with a sea of high-fives. The Nationals evened the score.

Reprieve proved temporary. Soon, the Giants were spilling out of their dugout, their playoff pedigree once again tested. They passed, sending the Nationals slinking away to another bitter winter.