DETROIT — Jared Goff threw two touchdown passes and the Detroit Lions beat the Tampa Bay Buccaneers 31-23 in a divisional-round playoff game Sunday, lifting the long-suffering franchise into the NFC championship for the first time in 32 years and just the second time in franchise history.

The Lions (14-5) have won two playoff games in a season for the first time since 1957, the last year they won the NFL title. They will play at San Francisco, the NFC’s top seed, next Sunday for a spot in the Super Bowl — a game they have never played in.

The Ravens, who will play in the AFC championship game next Sunday, beat both surviving NFC teams handily during the regular season. Baltimore routed the Lions 38-6 on Oct. 22 at M&T Bank Stadium. The Ravens beat the 49ers 33-19 on Christmas Night at San Francisco.

Jahmyr Gibbs ran through a huge hole for a tiebreaking, 31-yard touchdown early in the fourth quarter, and Goff made it a two-TD lead when he connected with Amon-Ra St. Brown for a 9-yard score with 6:22 left.

The Baltimore Banner thanks its sponsors. Become one.

Baker Mayfield threw three TD passes for Tampa Bay (10-9), including a 16-yard toss to Mike Evans that got the Bucs within one score with 4:37 left. Detroit couldn’t run out the clock on offense, giving Tampa Bay one last chance, but Mayfield’s pass over the middle was intercepted by linebacker Derrick Barnes, the QB’s second pick of the day.

The Lions kneeled to run out the clock as their fans stood, screamed and twirled white towels.