AP photo by Marcio Jose Sanchez / The Los Angeles Dodgers celebrate with Chris Taylor (3) after he hit a two-run homer in the bottom of the ninth inning to beat the St. Louis Cardinals on Wednesday night and advance to an NL Division Series against the San Francisco Giants.

LOS ANGELES — One big swing by Chris Taylor sent the Los Angeles Dodgers soaring and the St. Louis Cardinals crashing.

Taylor hit a two-run homer in the bottom of the ninth inning to give the Dodgers a 3-1 victory Wednesday night in a scintillating National League wild-card matchup.

Justin Turner homered early for the hosts and the 106-win Dodgers advanced to a best-of-five NL Division Series against the San Francisco Giants, who won 107 games during the regular season to barely hold off rival Los Angeles for the NL West title. Game 1 is Friday night in San Francisco.

"That's going to be be fun," Taylor said." Yeah, two of the best regular-season records of all time. We've been battling all year, so I expect a hard-fought series."

The Dodgers celebrated on the field before heading into their clubhouse to continue the party. Champagne and beer were poured over the heads of shirtless, goggle-wearing players, thrilled to have stayed alive for a shot at their division adversary from the Bay Area.

"One of the great rivalries in sports," Los Angeles manager Dave Roberts said. "It's happening."

The sellout crowd of 53,193 at Dodger Stadium hung on every pitch as the tension of a tie game built from the fourth inning on. Fans waved blue towels, futilely urging on the few balls launched into the outfield only to see them caught in a winner-take-all game between two of the NL's most storied and successful franchises.

The crowd was on its feet in the bottom of the ninth, anxiously waiting to see if the 2020 World Series champions could pull out a must-have win. Cody Bellinger got the Dodgers started when he drew a two-out walk from T.J. McFarland. Alex Reyes entered to face Taylor, and Bellinger stole second base.

"That's huge, knowing I don't have to do too much," said Taylor, who was batting in the No. 9 slot after entering to play left field as part of a double switch in the seventh. "It kind of settled me down a little bit."

Taylor then sent a 2-1 breaking ball into the left-field pavilion, triggering an explosion of cheers.

The versatile veteran struggled in September because of a recurring neck injury, and he came off the bench in the Dodgers' most important game of the season.

"Honestly, I was just trying to hit a single. Not trying to do too much," Taylor said after launching the fourth walk-off homer in the franchise's postseason history. "He gave me a good slider to hit, and I was able to get it up in the air."

It was MLB's fifth game-ending homer in a winner-take-all postseason game, after the Pittsburgh Pirates' Bill Mazeroski in the 1960 World Series, the New York Yankees' Chris Chambliss in the 1976 American League Championship Series, the Yankees' Aaron Boone in the 2003 ALCS and the Toronto Blue Jays' Edwin Encarnación in the 2016 AL wild-card matchup.

Taylor also made a nifty defensive play in the eighth, robbing Edmundo Sosa of a hit for the second out.

The Cardinals' Tommy Edman dropped a one-out single into right off closer Kenley Jansen in the top of the ninth and stole second, but Paul Goldschmidt took a called third strike and Tyler O'Neill went down swinging to end the threat. Edman went 3-for-5 with a run scored.

The Dodgers' bullpen stymied the St. Louis hitters, allowing just a pair of singles after the fifth inning.

"The whole bullpen stepped up. We've been doing it the whole year," Jansen said. "Off we go up north now."

Both teams had runners on in the sixth, seventh and eighth but couldn't push a run across.

"It was a grind all night," Turner said.

St. Louis finished 0-for-11 with runners in scoring position, stranding 11 overall.

The Cardinals went on a 17-game winning streak in September to grab the second wild-card spot, only to have their October dreams squelched.

"That's a clubhouse full of guys that are hurting," Cardinals manager Mike Shildt said.

Dueling aces Adam Wainwright of St. Louis and the Dodgers' Max Scherzer struggled with their control early in just the second winner-take-all game in postseason history with two starting pitchers who were both at least 37 years old. Wainwright is 40; Scherzer is 37.

"They were relentless," Wainwright said of the Dodgers. "We had our chances to win that game."

Wainwright and Scherzer issued two walks apiece through the first three innings. Scherzer's wild pitch led to a run in the first, and he plunked Harrison Bader in the fourth.

Turner tied it at 1 in the fourth on a leadoff shot into the Dodgers' bullpen in left. It was the first homer Wainwright has ever given up on a curveball in the postseason. Turner's 13 postseason homers are the most in franchise history.

St. Louis led 1-0 when Edman scored on Scherzer's wild pitch. Edman singled leading off, stole second base and went to third when O'Neill fouled out to right.

Scherzer left with one out in the fifth after giving up a leadoff single to Edman and a walk to Goldschmidt. He paced the dugout with his hands on his hips. Former Cardinal Joe Kelly got out of the jam after Goldschmidt reached third on a wild pitch.

Scherzer allowed one run and three hits, struck out four batters and walked three against his hometown team.

"We won the game. That's all that matters," he said.

Wainwright permitted one run and four hits in 5 1/3 innings. He struck out five batters and walked two.

The Dodgers had him on the ropes in the third, loading the bases with one out. He was within one ball of walking in the tying run before Trea Turner broke his bat grounding into an inning-ending double play on a 3-2 pitch.