The Rams hadn't beaten the 49ers in the regular season since 2018.
With both Los Angeles and San Francisco resting various players in preparation for the postseason, Rams backup quarterback Carson Wentz came through in crucial time to give LA a 21-20 win.
The win also gave the Rams the No. 6 seed in the NFC. With the remaining results as of Sunday afternoon, that means Los Angeles will travel to Detroit next weekend to play the Lions in the Wild Card Round.
In his first appearance for the Rams, Wentz used his legs to help the club win. He ran 17 times for 56 yards, including a 12-yard run with 4:56 remaining in the fourth quarter, leaving LA trailing 20-19. The Rams went for two and Wentz faked a run look before finding Tutu Atwell in the end zone for a successful conversion.
San Francisco had two more late chances, including a possession that began at its own 22 with 55 seconds left. But quarterback Sam Darnold — who was playing for the resting Brock Purdy — was sacked by defensive end Desjuan Johnson. Outside linebacker Byron Young recovered the loose ball and sealed the LA victory.
Wentz completed 17 of 24 passes for 163 yards with two touchdowns and one interception.
Puka Nacua set a rookie single-season record for receptions (105) and receiving yards (1,486) with his four catches for 41 yards with a touchdown.
On the other hand, Darnold was 16 of 26 for 189 yards with a touchdown. Elijah Mitchell led the way with 52 yards on 14 carries.
After finishing 5-12 last season, the Rams finish the 2023 season at 10-7 and a playoff spot. They will now wait to see what their window is for next weekend's game against Detroit.
As the NFC's No. 1 seed, the 12-5 49ers will face the conference's lowest remaining seed for the divisional round.