SANTA CLARA, Calif. -- For most of the regular season, the San Francisco 49ers followed a similar blueprint.

When they won, they did so convincingly. When they lost, they failed to make the big play or key drive at the end that would have turned the result in their favor.

Despite those failures in close and late situations, the 49ers insisted they could win that type of game. They just hadn't proved it.

Finally, that season-defining moment came Saturday night at Levi's Stadium against the Green Bay Packers. With hopes of the franchise's sixth Lombardi Trophy hanging in the balance, the Niners forged their first fourth-quarter comeback of the season and escaped with a thrilling 24-21 win.

With the victory, the Niners advanced to their third consecutive NFC Championship Game and fourth in the past five years. San Francisco will host the winner of Sunday's matchup between the Detroit Lions and Tampa Bay Buccaneers on Jan. 28.

Editor's Picks

2 Related

"We needed a win like that," defensive end Nick Bosa said. "We just haven't come from behind in a while."

Indeed, the last time the Niners had a comeback victory was in Week 17 last season, when they won on a field goal in overtime against the Las Vegas Raiders. What's more, the Niners entered Saturday's game with a record of 0-30 under coach Kyle Shanahan in games (including playoffs) that they trailed by seven or more points entering the fourth quarter. They were 0-3 in such games during the regular season.

On Saturday, the 49ers trailed 21-14 entering the final quarter. For the first three, the Niners had looked out of sorts, struggling to move the ball offensively and getting stops on defense. They lost wide receiver Deebo Samuel to a left shoulder injury in the first quarter, struggled to keep their footing under a steady rain, had a field goal blocked and racked up costly penalties.

With help from Packers miscues and a few timely short-yardage stops, the Niners managed to keep it close, but for much of the night it looked like a promising season was about to slip away. That was especially true for quarterback Brock Purdy, who was making his fourth career postseason start and first since suffering a torn ulnar collateral ligament in his right elbow in last year's NFC Championship Game loss to the Philadelphia Eagles.

Because of the rain, Purdy struggled to grip the ball, saying he began the game with a glove on his right, throwing hand but soon ditched it because he was "fed up" with it.

"There were sometimes where I'm dropping back and the ball was a little wet from the grass and it sort of affected some accuracy and stuff," Purdy said. "But that's football, so I've got to be better in that area."

Before the game's final drive, Purdy had looked uncomfortable in the pocket and was unable to efficiently get through his progressions to get the ball where it needed to go. Before San Francisco's winning touchdown drive, Purdy was 17-of-32 passing for 205 yards with a touchdown, and though he had no interceptions, the Packers had dropped a couple of golden opportunities Purdy had thrown them.

And then, when the Niners needed him most, Purdy delivered.

Down 21-17 with 6:18 to go and the ball at their 31, the 49ers marched 69 yards on 12 plays with running back Christian McCaffrey bursting up the middle for a 6-yard touchdown. On that final drive, Purdy was 6-of-7 passing for 47 yards with the lone incompletion a drop by tight end George Kittle. Purdy also rushed twice for 11 yards and picked up the first down that set up McCaffrey's touchdown run.

It was far from the usual, efficient Purdy performance the 49ers have come to expect, but it was meaningful for him to tally a winning drive in a high-stakes moment.

Welcome to the NFL offseason

Team-by-team offseason guide (ESPN+)Tracking coach openings, hiringsNFL draft order | Top draft prospectsRanking top 25 free agents (ESPN+)

"I think it was important," Purdy said. "We were all like, 'All right, this is it. This is our season.' ... And for all of us, and obviously for myself as a quarterback, it's good for confidence and all that. But we have too many good players on this team, so many players that are difference-makers and we've got a great defense. For us to not find a way, it's not right. For us to finally have a game like this and pull through at the end was huge for all of us."

Following McCaffrey's touchdown, the Packers got the ball back with three timeouts and 1:07 to potentially win the game or at least send it to overtime. San Francisco linebacker Dre Greenlaw dashed those hopes on the fourth play of Green Bay's ensuing possession, stepping in front of a pass quarterback Jordan Love intended for wide receiver Christian Watson and intercepting it.

Even that play came with drama as Greenlaw frantically raced all over the field attempting to score a touchdown as his teammates, coaches and Niners fans screamed for him to go down. It was Greenlaw's second interception of the night, and he had attempted a similar return on his first one. According to NFL Next Gen Stats, Greenlaw covered 101 yards of total distance on the two interception returns but only gained 25 yards on them.

"Fred [Warner] told me I was supposed to get a pick-six," Greenlaw said, laughing. "So, I mean, it was kind of his fault. ... But yeah, I know I need to go down."

After the victory, the 49ers locker room was happy, but relief seemed to be the emotion of the day. They had just finished what Kittle said "probably wasn't our best game of football that we've played all year" and found a way to win. It was San Francisco's fifth straight playoff win against the Packers, tied with the Steelers (against the Colts) for the longest postseason win streak against a single opponent in league history. It was also the Niners' 37th all-time playoff win, tying them with the Packers and New England Patriots for the most in NFL playoff history.

Until the last few minutes, none of it was pretty, but it didn't have to be. Another trip to the Super Bowl will be on the line next week, and none of the Niners care how they get there, so long as they do.

"We just want to do everything we can to play our best because we feel we can win every game when we do that," Shanahan said. "We don't feel like we did that today, but we still found a way to win. ... I thought that was as big of a mental challenge and just a character game as any game I've been a part of. ... It was a gut check for everybody and couldn't be more proud of the people in there and just how they persevered."