SANTA CLARA, Calif. — The San Francisco 49ers are still alive in their quest for a sixth Lombardi Trophy. Barely.

The 49ers overcame a 17-point halftime deficit to the Detroit Lions, as third-quarter heroics by wide receiver Brandon Aiyuk and quarterback Brock Purdy helped San Francisco rally to a 34-31 victory over Detroit in the NFC Championship Game on Sunday, denying the Lions their first Super Bowl appearance.

Christian McCaffrey scored twice for the 49ers, who will play the Kansas City Chiefs in Super Bowl LVIII on Feb. 11 at Allegiant Stadium in Las Vegas in a rematch of their Super Bowl showdown four years ago.

San Francisco 49ers

For most of the season, the 49ers were the perfect front-runners. They often raced out to big leads, forced opponents to throw the entire second half and put games away.

That approach left many wondering if the Niners were made of the right stuff when the game was on the line. If last week’s win against the Green Bay Packers wasn’t enough evidence, the 49ers left no doubt Sunday against the Lions.

The 49ers entered halftime trailing by 17 with seemingly little chance of getting back into it. But these veteran-led Niners never relented, rattling off 27 straight points to forge a tie with the 2012 version of the 49ers for the biggest comeback in NFC Championship Game history.

And now, after a series of near misses and devastating losses before the Super Bowl, the Niners will get their long-awaited shot at the franchise’s sixth Lombardi Trophy. In a fitting twist, they’ll do it against the Chiefs, who erased their own deficit in Super Bowl LIV to send the Niners on their four-year journey to get back to the league’s biggest stage.

QB breakdown: After a rough first half in which he was under pressure often and threw his first career postseason interception, Purdy decimated the Lions with his arm and his legs. Purdy had a pair of 21-yard scrambles in key moments, finishing with 48 yards on five carries and completing 20 of 31 passes for 267 yards and a touchdown with the interception.

While Purdy didn’t wait until the final drive of the fourth quarter this week, he did save his best for last to help the Niners move on.

Biggest hole in the game plan: How the Niners’ defense would hold up against Detroit’s running game was the biggest question facing San Francisco this week. And while much of the Lions’ success was the result of flat-out physical dominance, Niners defensive coordinator Steve Wilks didn’t offer much in the way of adjustments to slow it down.

At various points in the season, the Niners dabbled with five-man fronts to change it up and give opposing offenses something to think about. Aside from a third-quarter surge, the Niners struggled to stop the run as Detroit finished with 182 yards on 29 attempts.

Describe the game in two words: Comeback kids. So much was made this season of the Niners’ inability to author comebacks, but apparently they were saving it for the postseason, as they erased a second-half deficit for the second week in a row to advance to Super Bowl LVIII. The Niners join the 1994 Chargers as the only teams with multiple seven-point, second-half playoff comebacks prior to reaching the Super Bowl. That Chargers team lost to San Francisco in Super Bowl XXIX (49-26). — Nick Wagoner

Next game: vs. Kansas City Chiefs in Super Bowl LVIII, Feb. 11 (6:30 p.m. ET, CBS)

Detroit Lions

So close, but so far.

It was a tale of two halves for the Lions as they blew a 17-point lead at halftime, falling one game short of the first Super Bowl appearance in franchise history. The third quarter was the game-changer, as the Lions were outscored 17-0 to cough up a 24-7 halftime lead thanks to a circus catch by Aiyuk and a costly fumble by Jahmyr Gibbs.

Detroit has now lost 12 straight playoff games on the road, extending its mark for the longest postseason road losing streak in NFL history.

Describe the game in two words: Questionable decisions. Lions head coach Dan Campbell is known for being aggressive and made some tough calls, notably failing twice on fourth down in the second half, which could have changed things down the stretch.

Troubling trend: Third-quarter woes. Not only were the Lions held scoreless coming out of the first half, but they were outgained 170-42, which was their second-worst yards differential in a quarter this season. Gibbs’ lost fumble was their first turnover of the postseason, and they dropped two passes on third and fourth downs, which was tied for their most in a game this season.

QB breakdown: Jared Goff didn’t have to have his greatest performance in the air, with the Lions running so well in the first half, but he continued his playoff streak of no interceptions. Goff passed for 273 yards while going 25-for-41, but he didn’t throw a touchdown pass until the waning moments of the game. He nearly reached a Super Bowl with his second team, where he would have joined Tom Brady, Peyton Manning, Kurt Warner and Craig Morton as the only QBs to start a Super Bowl with multiple teams. — Eric Woodyard