SAN FRANCISCO (AP) -- Joe Panik scored the go-ahead run in the seventh inning on Aaron Barrett's bases-loaded wild pitch, and the San Francisco Giants beat the Washington Nationals 3-2 on Tuesday night to return to the NL Championship Series.

The wild-card Giants took Game 4 in the best-of-five Division Series and eliminated the Nationals by scoring on a bases-loaded walk, a groundout and a wild pitch. Hunter Pence turned in a defensive gem in right field.

Santiago Casilla put the potential tying run aboard in the ninth on a two-out walk to Bryce Harper, then retired Wilson Ramos on a grounder to end it. Casilla was mobbed on the mound as fireworks shot off from the center-field scoreboard.

San Francisco travels to St. Louis for Game 1 on Saturday. It's a rematch of the 2012 NLCS, when the Giants rallied from a 3-1 deficit to beat the Cardinals on the way to their second World Series championship in three years.

More From 1460 ESPN