San Francisco 49ers running back Christian McCaffrey scores a rushing touchdown during the second half of an NFC divisional playoff game against the Green Bay Packers on Saturday in Santa Clara, Calif.
                                 AP photo

San Francisco 49ers running back Christian McCaffrey scores a rushing touchdown during the second half of an NFC divisional playoff game against the Green Bay Packers on Saturday in Santa Clara, Calif.

AP photo

<p>San Francisco 49ers head coach Kyle Shanahan speaks at a news conference after an NFC divisional playoff game against the Green Bay Packers on Saturday in Santa Clara, Calif.</p>
                                 <p>AP photo</p>

San Francisco 49ers head coach Kyle Shanahan speaks at a news conference after an NFC divisional playoff game against the Green Bay Packers on Saturday in Santa Clara, Calif.

AP photo

<p>San Francisco 49ers quarterback Brock Purdy (13) throws a pass against the Green Bay Packers during the fourth quarter of an NFC divisional playoff game Saturday in Santa Clara, Calif.</p>
                                 <p>AP photo</p>

San Francisco 49ers quarterback Brock Purdy (13) throws a pass against the Green Bay Packers during the fourth quarter of an NFC divisional playoff game Saturday in Santa Clara, Calif.

AP photo

SANTA CLARA, Calif. — The San Francisco 49ers spent most of the season as dominant front-runners, racing out to early leads and putting teams away with relative ease.

They flipped the script in their playoff opener, mounting a late-game comeback that showed they are able to win even when things aren’t going smoothly.

The Niners overcame a off night with a late-game touchdown drive that gave them a 24-21 comeback win over the Green Bay Packers in the divisional round on Saturday.

“It does check the box. Whatever that means,” All-Pro left tackle Trent Williams said. “I really do think being able to grind it out and being able to go and get a touchdown against a really good defense and put the game in our hands, I think that is important. We do need that. In a lot of our wins, I was off in the fourth quarter. It doesn’t help us for next week, but it does give us a little token of confidence that hey, we can get it done.”

Related Video

Brock Purdy went from shaky to clutch late in the fourth quarter, completing six of seven passes for 47 yards on the game-winning drive that was capped by Christian McCaffrey’s 6-yard run with 1:07 to play.

It was Purdy’s first career game-winning drive that required him to do anything more than just kneel down. His only previous one came in an overtime win last season at Las Vegas when he took a knee following an interception to set up a game-winning field goal.

The Niners defense that got gashed for some big plays early sealed the win with Dre Greenlaw’s second interception, sending San Francisco to its third straight NFC championship game.

“Everything is not going to go perfectly in a game,” defensive tackle Arik Armstead said. “There’s going to be mistakes, there’s going to be big plays. But you just have to keep fighting and that’s the type of team that we have. We’re always going to fight until the end.”

Now the Niners get ready to take on the Detroit Lions at home Sunday, when they will hope to get back to the Super Bowl after losing in this round the past two seasons.

WHAT’S WORKING

Giving the ball to McCaffrey. It wasn’t a heavy usage game on the ground for McCaffrey, who had 17 carries. But he delivered in a big way. He scored on a 39-yard run in the third quarter and then provided the game-winner in the fourth quarter. He finished with 128 yards from scrimmage and tied a franchise record by scoring at least one TD in four straight playoff games.

WHAT NEEDS HELP

Special teams. The issues on special teams from the season nearly doomed the Niners in their playoff opener. Rookie Jake Moody had a 48-yard field goal blocked at the end of the first half for San Francisco’s first missed kick in the playoffs since the 2012 NFC title game. The Niners then allowed a 73-yard kickoff return in the third quarter to set up a Green Bay touchdown.

STOCK UP

Greenlaw. This hasn’t been Greenlaw’s best season as he has been hampered by several injuries, but he came up in a big way on Saturday. He stopped Jordan Love on a fourth-down sneak in the red zone in the second quarter, had an interception late in the third quarter to set up a field goal and then sealed the win with another pick.

He was the first Niners player with two INTs in a playoff game since Eric Davis did it in the 1994 NFC title game against Dallas.

STOCK DOWN

CB Ambry Thomas. The Packers picked on Thomas all game with success. Love completed all five passes he threw with Thomas in coverage for 74 yards, according to Pro Football Focus. Thomas was also called for pass interference twice for 54 yards.

INJURIES

WR Deebo Samuel left the game early with a left shoulder injury. Tests showed no broken bones but Samuel is still in pain, according to coach Kyle Shanahan. The Niners will have a better idea on Wednesday about his availability for the game.

KEY NUMBER

7 — San Francisco has had seven winning records in the last 21 seasons — tied for the 22nd most in the NFL. The Niners have made it to the NFC title game in all seven of those seasons, trailing only the Patriots for most conference championship game appearances in that span.

NEXT STEPS

The 49ers will be playing in their record 19th conference championship game since the merger. They are 7-11 in their previous trips and have lost the last two seasons against Philadelphia and the Rams. The last team to lose a conference title game in three straight seasons was the Eagles from 2001-03.