CINCINNATI — Buster Posey insisted all along — even after San Francisco lost the first two at home — that his team was far from done, no matter how long the odds.

Turns out, he was right. And the NL batting champion had a lot to do with this most Giant comeback.

Posey hit the third grand slam in Giants postseason history on Thursday, and San Francisco pulled off an unprecedented revival, moving into the championship series with a 6-4 victory over the Cincinnati Reds.

They’ll play either Washington or St. Louis for the NL pennant starting Sunday.

“We could go up against anybody at any time,” shortstop Brandon Crawford said. “Being down 2-0 and coming back and winning three at their place, it’s an unbelievable feeling.”

The Giants became only the eighth team to win a five-game playoff series after falling behind 2-0. Major League Baseball’s changed playoff format this season allowed them to become the first to take a best-of-five by winning the last three on the road.

With one swing, Posey made it possible.

“I don’t think anybody gave up,” he said.

Posey’s second career grand slam off Mat Latos put the Giants up 6-0 in the fifth and sparked a joyous scrum in the San Francisco dugout. The ball smacked off the front of the upper deck in left field, just above Latos’ name on the video board.

“That gave us some breathing room,” reliever Jeremy Affeldt said. “We were all excited.”

Will Clark, in the 1989 NLCS, and Chuck Hiller, in the 1962 World Series, hit the other Giants slams in the postseason.

Matt Cain and the bullpen held on, with more help from Posey. The All-Star catcher threw out Jay Bruce at third base to snuff out a sixth-inning rally that cut it to 6-3. The Giants also had a pair of diving catches that preserved the lead in the eighth.

Ryan Ludwick singled home a run in the ninth off Sergio Romo. With two runners aboard, Romo fanned Scott Rolen to end it. The Giants raised their arms, hugged and huddled by the side of the mound, bouncing in unison.

Then they were off to the visiting clubhouse to start spraying some bubbly.

In Cincinnati, the home-field meltdown that felt sickeningly familiar. The Reds haven’t won a home playoff game in 17 years. After taking the first two on the West Coast, all they needed was one more at home, where they hadn’t dropped three straight all season.

“You get tired of the disappointments, but then you get over it,” manager Dusty Baker said. “It hurts big-time.”

Once Posey connected, the Reds were the ones facing an unprecedented comeback. They’ve never overcome a six-run deficit in the playoffs, according to STATS LLC.

Couldn’t do it this time, either.

The Giants won it all in 2010, when they never trailed in any of their three postseason series. They beat the Braves 3-1 in the division series, knocked out the Phillies 4-2 for the NL title, then took four of five from Texas for their sixth World Series title and their first since they moved from New York to San Francisco in 1958.

They really had to scramble this season to get another shot at it.

The bullpen took a huge hit when closer Brian Wilson blew out his elbow, and that was just the start. All-Star game MVP Melky Cabrera got a 50-game suspension in August after a positive testosterone test, taking a .346 hitter out of their lineup. The Giants have decided not to bring him back, even though he’s eligible to return for the NL championship series.

Two-time Cy Young winner Tim Lincecum pitched so poorly — 15 losses — that he got relegated to the bullpen for the division series.

And don’t forget that Posey was coming off a broken leg that wiped out most of his 2011 season, making a great comeback of his own.

“Unreal,” Romo said, with champagne dripping off his scraggly beard. “That guy’s definitely the MVP of our team. We believe he’s the MVP of the league. We wouldn’t be here without him, that’s for dang sure. He’s the one that’s been the face of the team all season long. What a great story with all he’s been through last year.”

They pulled it all together during the streak of three improbable wins in Cincinnati.

The Reds will remember the first inning of the series, where everything changed. Ace Johnny Cueto pulled muscles in his right side and had to leave the game. He wound up getting dropped from the playoff roster because of the injury.

Latos pulled them through that opening game, pitching in relief on short rest for a 5-2 win. Latos came to Cincinnati from the Padres at a high price — two first-round draft picks — and with a clear purpose in the offseason. He was expected to take them to the next level.

The right-hander allowed three hits through the first four innings, then fell apart in the fifth. Brandon Crawford had an RBI triple and scored on shortstop Zack Cozart’s error. A four-pitch walk and a single loaded the bases for Posey.

As soon as he connected, Reds catcher Ryan Hanigan stood and turned away, unable to watch the ball head for the seats.

Cincinnati’s 17-year history of playoff futility was about to go on.

NOTES: Posey’s other career grand slam came on July 7, 2010 at Milwaukee. ... The Reds are 3-3 in winner-take-all playoff games, including 1-2 in best-of-five series and 2-1 in best-of-seven series. .. Teams that lose the first two games in a best-of-five series are 7-59 all-time. ... Cain gave up six hits and three runs in 6 2-3 innings, the longest appearance by a Giants starter during the series.