The 49ers (12-3) beat the Rams 34-31 on a 33-yard Robbie Gould field goal as time expired. San Francisco pulled off the victory despite being out-gained in total yardage and losing the turnover and time of possession battles.
"You get used to [close games] happening, but your body still feels the same: Not great," 49ers coach Kyle Shanahan told reporters. "We'll go rest after this, but it's a lot of fun. I mean, as long as you win them, it's a lot of fun."
Los Angeles (8-7) is just the second team since 2009 to lose in the Super Bowl and miss the playoffs the following season. The Carolina Panthers suffered the same fate in 2016.
Los Angeles and San Francisco alternated punts on the next three drives before Rams running back Todd Gurley scored a five-yard rushing touchdown at the start of the second quarter. The 49ers answered with a five-play, 75-yard touchdown drive. Deebo Samuel gave the 49ers a 14-10 edge with a 19-yard rushing score to end that drive.
Gurley rushed for another score on the Rams' next drive, but the 49ers answered once again when Raheem Mostert rushed for a 16-yard touchdown.
The Rams attempted to respond on their next drive, before Fred Warner intercepted Goff and had a 46-yard touchdown return, giving San Francisco a 24-21 lead at halftime.
"We were in man coverage and the running back kind of checked in the protection and then ran a flat route. I hugged up on him and I think [Goff] probably would want to have that one back, but he just tossed it up and I took it.
"I took it home."
The Rams snatched the lead back with a seven-play, 68-yard scoring drive in the third quarter. Goff connected with Cooper Kupp on a 22-yard touchdown toss to end that drive, giving the Rams a 28-24 lead.
The 49ers took a 31-28 lead with 6:06 remaining when Jimmy Garoppolo threw a seven-yard touchdown pass to George Kittle. Greg Zuerlein hit a game-tying field goal for the Rams on the next drive.
Garoppolo led a nine-play, 60-yard drive on the game's final possession, marching the 49ers to the 15-yard line and putting Gould in position to hit the game-winning field goal.
"Congratulations to the 49ers. Great win by them. It was a great, hard-fought battle back and forth, comes down to the wire," Rams coach Sean McVay said. "They made the plays to be able to win it.
"We didn't do a good enough job of that and unfortunately, that means that our postseason chances are eliminated, but I know this, we've got an opportunity to finish this season the right way."
Goff completed 27 of 46 passes for 323 yards, two scores and an interception in the loss. Garoppolo completed 16 of 27 passes for 248 yards, one score and two interceptions. Dante Fowler Jr. had six tackles and 2.5 sacks for the Rams.
The 49ers end the regular season with a matchup against the Seattle Seahawks at 4:25 p.m. EST Sunday, Dec. 29 at CenturyLink Field in Seattle. The Rams host the Arizona Cardinals at 4:25 p.m. Dec. 29 in Los Angeles.