Jauan Jennings caught a 14-yard touchdown pass from Jimmy Garoppolo with 26 seconds left in regulation for the 49ers (10-7), who are postseason-bound for only the second time in eight years.
San Francisco rallied from an early 17-point deficit for their sixth consecutive win over the playoff-bound Rams (12-5), who won the division title anyway thanks to Seattle’s victory over Arizona.
Sixth-seeded San Francisco will play at Dallas next week, while the fourth-seeded Rams will host the Cardinals in the first playoff game in SoFi Stadium history.
Deebo Samuel rushed for a touchdown and threw a scoring pass to Jennings for the Niners, who made a deliberate 69-yard drive to open overtime. The Rams got the ball back, but Thomas picked off Matthew Stafford’s long throw down the Rams’ sideline.
San Francisco now has its longest winning streak in this rivalry since the 1990s.
Cooper Kupp caught a go-ahead TD pass from Stafford with 2:26 to play for the Rams, whose five-game winning streak ended.
Stafford passed for 238 yards and three touchdowns while winning the first division title of his 13-year NFL career, but Los Angeles is headed into the postseason on a decidedly down note.
The Rams went ahead 24-17 on Kupp’s 4-yard TD catch, and the teams traded punts before Garoppolo led the Niners on an 88-yard drive in 61 seconds, capped by Jennings’ score over the middle. San Francisco won the toss and capitalized.
Garoppolo played through an injured right thumb and improved to 6-0 against the Rams, but Samuel made the most impressive throw of the day when he hit Jennings with a wobbly 24-yard TD pass over the baffled Rams defense for the tying score late in the third quarter.
Jalen Ramsey kept the Rams in the game with a diving interception of a tipped ball in the end zone with 7:42 to play when San Francisco was in range for a go-ahead field goal.
Kupp became the fourth player in NFL history to lead the league in receptions, yards receiving and TD catches this season after finishing with seven receptions for 118 yards. He made two huge catches on the Rams’ go-ahead drive, but didn’t get another touch.
Los Angeles dominated possession in the first half and led 17-0 on Higbee’s leaping 15-yard TD catch 6:44 before halftime, but San Francisco drove for its first points on Gould’s field goal at the halftime gun.
The Niners went 75 yards immediately after halftime, capped by Samuel’s 16-yard TD run. San Francisco’s second drive began with 10 consecutive runs before Samuel hit Jennings.
CAM THE RAM
Cam Akers ran the ball five times and caught three passes in his season debut for Los Angeles. The second-year pro tore his Achilles tendon shortly before training camp, but made an exceptionally quick recovery.
The 49ers played without star left tackle Trent Williams, who couldn’t return from an elbow injury incurred last week. Backup guard Colton McKivitz started at left tackle.
Niners punter Mitch Wishnowsky was sidelined in the first half by a concussion, forcing Gould to punt. Safety Talanoa Hufanga went out in the first half with a knee injury.
Rams safety Jordan Fuller injured his right foot early in the fourth quarter.
49ers: Visit Dallas.
Rams: Host Arizona.