(CBS) It’s a rally that will live on in Cubs lore.

On the brink of heading back to Wrigley Field for a winner-take-all Game 5 they wanted no part of, the Cubs responded with a magical ninth inning Tuesday night, scoring four times off the stunned Giants and their struggling bullpen to win Game 4 of the National League Divisional Series, 6-5. It clinched the series 3-1, sent the Cubs into the NLCS in consecutive seasons for the first time in franchise history and even had cool, calm manager Joe Maddon admitting it was “stressful.”

“That’s crazy stuff,” Maddon said in a postgame interview on 670 The Score. “Everybody was engaged, all hands on deck.

“Nobody quits in this group.”

The rally was in stark contrast to Chicago’s performance in being stymied for eight innings by San Francisco left-hander Matt Moore.

After a lead-off single by Kris Bryant and a walk by Anthony Rizzo on a full count, Ben Zobrist drilled an RBI double down the right-field line. Pinch-hitter Willson Contreras then knocked a two-run single up the middle to tie the game 5-5.

Jason Heyward followed with a bunt that forced Contreras out at second, but a throwing error to first in trying for the double play went into the stands, sending Heyward to second. Javier Baez then hit the go-ahead RBI single up the middle.

“Willson and Javy had really mature at-bats,” Cubs general manager Jed Hoyer said.

Added Zobrist: “You just kind of had a feeling something good was going to happen.”

Aroldis Chapman struck out the side in the ninth inning for the save. Hector Rondon got the win by pitching a scoreless eighth inning.

“That’s the craziest thing I’ve ever seen,” Cubs veteran right-hander John Lackey said on 670 The Score.

Behind a dominating performance from Moore, it looked like San Francisco would comfortably send the series back to Chicago for a Game 5. He threw eight innings of two-run ball, allowing just two hits and striking out 10 while walking two. His pitch count was at 120 when he was pulled, with manager Bruce Bochy turning to a bullpen that had been the team’s weakness for much of the season.

Bochy used five relievers in the ninth inning, but none had the answer.

The Giants controlled the game most of the night. After Cubs catcher David Ross’ solo homer tied the game 1-1 in the top of the third, the Giants took the lead again in the fourth, when Moore drilled an RBI single off Lackey and Denard Span followed with an RBI on a fielder’s choice for a 3-1 lead.

Lackey went just four innings, allowing three runs on seven hits, two walks and four strikeouts.

A Ross sacrifice fly cut Chicago’s deficit to 3-2 in the top of the fifth, but San Francisco responded with two runs of its own on a Conor Gillaspie RBI single and a Joe Panik sacrifice fly.

The Cubs will host Game 1 of the NLCS on Saturday night at Wrigley Field. They’ll play the winner of the Dodgers-Nationals series, which has Game 5 set for Thursday.

Jon Lester will be in line to start Game 1 for the Cubs.

“Pressure, expectations — I want our guys to thrive on those words for years to come,” Maddon said.

Added Rizzo: “We”re going to ride this. Every step of the way, we’re going to earn it.”