Giants reliever Sergio Romo closes out the Reds. (Andy Lyons/Getty Images)

With booze spraying, music blaring and ballplayers dancing all around him, San Francisco Giants third-base coach Tim Flannery leaned against a locker with a bottle of champagne in his hand and reflected on a team that made molehills out of mountains all season long.

The Giants lost reliever Brian Wilson to Tommy John surgery. Outfielder Melky Cabrera got hit with a 50-game suspension. The Los Angeles Dodgers reloaded late in the season. And the Giants survived it all. So to Flannery, a former ballplayer, it’s no surprise the Giants didn’t flinch when they came to Cincinnati trailing two games to none in a best-of-five series, fully aware that no National League team had ever overcome such a deficit.

“These guys must not watch it or believe it or understand it,” he said. “They just show up and play together.”

The Giants capped a historic comeback Thursday afternoon with a drama-filled 6-4 victory over the Cincinnati Reds in Game 5 of the National League Division Series in front of 44,142 fans at the Great American Ball Park. San Francisco advances to face the winner of the St. Louis-Washington series in the National League Championship Series, which is scheduled to begin Sunday.

If the Nationals beat the Cardinals in Game 5 Friday night, they'll face a Giants’ squad much more energized than the one they saw in the regular season. Washington held a 5-1 advantage over the Giants this season, outscoring San Francisco, 45-24.

On Thursday, the Giants relied on strong pitching when they needed it most and one timely swing of the bat by catcher Buster Posey, whose fifth-inning grand slam buried the Reds in a hole from which they didn’t emerge.

“I just saw that he made a good swing, and his reaction kind of said it all,” said Giants starter Matt Cain, who picked up the win, allowing three runs and six hits in 52 / 3 innings. “He knew he got it.”

Since each league began staging a five-game division series in 1995, 21 National League teams had previously tried and failed to overcome a 2-0 deficit. In advancing, the Giants had to not only win three straight against the team that posted baseball’s second-best record, but they had to win all three on the road against a Reds squad that hadn’t lost three straight at home all season.

“Some things are hard to explain,” Giants Manager Bruce Bochy said.

In the home team's clubhouse, the Cincinnati collapse didn’t sit well with players or Manager Dusty Baker. Sure, they’d lost ace Johnny Cueto, who pulled muscles in his side in Game 1, after facing only one batter, but the Reds still needed only one win at home.

“You get tired of the disappointments,” Baker said. “But then you get over it. It hurts, big time. I’m a strong man, and usually I get over hurts and it makes me stronger when I come back.”

On Thursday, Cincinnati starter Mat Latos held the Giants to just three hits through four innings, but outfield Gregor Blanco led off the fifth with a single to left. He’d score the game’s first run one batter later when Brandon Crawford ripped a triple into the right field corner. Crawford scored on a fielding error by Reds shortstop Zack Cozart.

The Giants then loaded the bases for Posey, who drilled a 2-2 pitch 434 feet over the left-center wall, hitting the electronic scoreboard just below the second deck. The grand slam lifted the Giants to a 6-0 lead.

“When you see . . . ball disappear and go as high as it did in this ballpark, it’s a no-doubter,” right fielder Hunter Pence said.

“We knew it was still going to be a fight,” Giants reliever Jeremy Affeldt said.

The Reds got on the scoreboard in the fifth when Brandon Phillips doubled to center, knocking in two. They added another in the sixth and managed to bring the tying run to the plate in each of the final four innings.

They stranded two in the seventh, two more in the eighth (courtesy of Angel Pagan’s diving catch in center), and in the ninth, after adding a run that cut the Giants’ lead to 6-4, the Reds again had two runners on base.

With thousands of red-clad fans twirling white towels, Scott Rolen stepped to the plate to face Sergio Romo, but Rolen didn't stay long. He went down swinging, ending the Reds season and punching the Giants’ ticket into the next round of postseason.

No one could’ve scripted the NLDS quite like this, but the Giants have been doing things their own way all season long, brushing aside trials and obstacles alike.

“In my mind, I knew it was going to have to take something weird,” Flannery said during the postgame celebration. “I knew we were going to have to catch a break. I knew there was going to have to be pitching and heroes. I think there was all of that.”