SANTA CLARA, Calif. — Christian McCaffrey scored his second touchdown on a 6-yard run with 1:07 to play, and the San Francisco 49ers mounted their first second-half comeback of the season to beat the Green Bay Packers 24-21 in a divisional-round playoff game on Saturday night.

After spending all regular season as front-runners, the Niners (13-5) needed to come from behind for a change, and Brock Purdy and McCaffrey did just enough on the last drive to send San Francisco to its third straight NFC championship game. The Niners will host the winner of Sunday’s game between Tampa Bay and Detroit next weekend for a spot in the Super Bowl.

The Ravens, who advanced to the AFC championship game with their win over the Houston Texans on Saturday, had decisive wins over the 49ers and Lions during the regular season.

Purdy went 6-for-7 for 47 yards on the decisive drive, converting a third down to Brandon Aiyuk and then a 17-yarder to Chris Conley.

The Baltimore Banner thanks its sponsors. Become one.

McCaffrey finished it with his run on third-and-short, and the 49ers’ defense held on from there. Dre Greenlaw intercepted Jordan Love for the second time to seal San Francisco’s fifth straight playoff win over Green Bay (10-9).

That last throw across his body was one of the few mistakes by Love, who had given the Packers the lead with two TD passes in the third quarter. But his first full season as the starter in place of Aaron Rodgers had a disappointing ending.

Love had put the Niners in the unusual spot of playing from behind. Green Bay converted a third-and-15 when Ambry Thomas was called for a 41-yard pass interference call against Bo Melton. Love and Melton then connected on the next play for a wide-open 19-yard touchdown aided by Tashaun Gipson slipping on the wet turf in coverage.

After McCaffrey put San Francisco back in the lead with a 39-yard TD run, Green Bay struck quickly thanks to a 73-yard kick return by All-Pro Keisean Nixon that he fumbled, only to have teammate Eric Wilson recover.

Four plays later, Love threw a 2-yard touchdown pass to Tyler Kraft and the Packers extended the lead to 21-14 on a 2-point conversion pass to Aaron Jones.

The Baltimore Banner thanks its sponsors. Become one.

The Niners were the first team to make the playoffs in 13 seasons without overcoming a second-half deficit to win a game.

They got a 52-yard field goal from Jake Moody on the first play of the fourth quarter to make it a four-point game, and it stayed there when rookie Anders Carlson missed a 41-yarder for Green Bay.

The Packers moved the ball easily in the first half, getting into the red zone on three straight drives to open the game. But they couldn’t finish any of them, setting for two field goals and getting stopped on a fourth-and-1 sneak. They became the first team in 20 years to reach the red zone on their first three drives of a playoff game without getting a TD.

The Niners made them pay for that with Purdy hitting George Kittle on a 32-yard pass on the run for a TD that gave San Francisco the lead.

But San Francisco squandered another chance late in the half when coach Kyle Shanahan wasted time before settling for a 48-yard field goal attempt by Moody that was blocked by Colby Wooden to send the Niners into the half with a 7-6 lead.

More From The Banner