ST. LOUIS (AP) — The St. Louis Cardinals will take on the San Francisco Giants in the National League Championship Series after both came up with winning runs in the seventh inning, both won 3-2 and both clinched 3-1 series victories on Tuesday.

St. Louis edged the Los Angeles Dodgers while the Giants overcame Washington. Now the two teams that have split the past four NLCS between them will face off for a spot in the World Series.

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 4-3.

In St. Louis, the key moment came in the bottom of the seventh inning with the Cardinals trailing 2-0. Matt Adams got hold of a Clayton Kershaw pitch and blasted it into the bullpen beyond right field for a three-run homer that put the hosts ahead for good.

The bottom of the seventh also proved decisive in San Francisco, where the Giants had loaded the bases when Nationals pitcher Aaron Barrett threw a wild pitch, allowing the go-ahead run.

The likelihood of Adams hitting a game-winning homer off Kershaw seemed remote, given that the Dodgers ace had only allowed one homer to left-handed hitters all season while posting a remarkable regular-season record of 21-3 with a 1.77 ERA.

However Kershaw's has developed an unfortunate habit of saving his worst for playoff games. He has a 0-3 record with a 9.72 ERA in his past three postseason appearances, including St. Louis' clinching Game 6 victory over the Dodgers in the NLCS last year.

Kershaw pitched on three days' rest for the second time in his career. He was dominant into the seventh, as he was in Game 1, but again started the inning with three straight hits; the third of which was Adams' homer.

Adams thrust his hands over his head in the batter's box then jumped several times as he ran down the first base line.

"I was just super-excited, I didn't know what I was doing ... I knew I was jumping for joy," Adams said.

"I don't think I touched the ground the whole way around the bases. Definitely the highlight of my career. ... I will never, ever forget this."

A stunned Kershaw bent over on the mound, head hung and hands on his knees.

"The season ended and I was a big part of the reason why," Kershaw said. "I can't really put it into words, Just bad deja vu all over again."

Cardinals closer Trevor Rosenthal allowed two Dodgers runners in the ninth inning before retiring Carl Crawford on a game-ending groundout.

Washington's season ended with a third-straight one-run defeat to the Giants; the worst of which was an agonizing defeat in an 18-inning Game 2.

Barrett's bases-loaded wild pitch allowed Joe Panik to score from third, and it almost got worse for the Nationals immediately afterward.

Barrett got set to intentionally walk Pablo Sandoval to load the bases again, but again his pitch sailed over the head of the catcher, who scrambled to retrieve the ball and threw to Barrett, who had rushed in to cover home plate. The pitcher took the relay and tagged out a sliding Buster Posey.

The call was upheld after a replay review of 1 minute, 57 seconds, denying San Francisco an insurance run.

Washington had a chance to score the tying run in the ninth, when Giants closer Santiago Casilla issued a walk to Bryce Harper with two outs. However Casilla then retired Wilson Ramos on a grounder to end it.

San Francisco right-fielder Hunter Pence produced the play of the night when he slammed his back into an archway on the wall to take a catch and rob Jayson Werth of extra bases in the sixth.

"That catch he made was unreal. It really brought momentum back in our favor," Posey said.