Robbie Gould kicked a 42-yard field goal as time expired to give the San Francisco 49ers a 23-20 victory and a season-series sweep over the host Los Angeles Rams on Sunday afternoon.
It was Gould's third field goal of the game.
Taking over at their own 20 with 2:10 left in a 20-20 game, the 49ers drove to the Los Angeles 24 on the strength of three completions from Nick Mullens to Deebo Samuel.
The veteran Gould, who earlier had connected from 46 and 44 yards, trotted onto the field with 4 seconds remaining and calmly split the uprights as time ran out to end San Francisco's three-game losing streak.
Mullens passed for 252 yards with one interception to lead the 49ers (5-6), who benefited from the return from long absences by Samuel, who caught 11 passes for 133 yards, Raheem Mostert, who rushed for 43 yards and a score, and Richard Sherman, who intercepted a pass.
The Rams' Jared Goff threw for 198 yards but suffered a pair of interceptions in a game that featured seven turnovers and two defensive scores.
Cam Akers scored the only offensive touchdown of the game for the Rams on a 1-yard run. The Rams (7-4) had won two consecutive games.
Akers was the game's leading rusher with 84 yards on nine carries.
The Rams, who were beaten 24-16 on the road by the 49ers in Week 6, trailed 17-3 late in the third quarter before scoring the game's next 17 points over a span of just 4:21 to take a three-point lead on Akers' short plunge with 14:17 remaining in the game.
The flurry included a 20-yard fumble return by Troy Hill on the first play from scrimmage following a 41-yard Matt Gay field goal.
Gould's 44-yard field goal, his second of the game, got the 49ers even at 20-all and set up the exciting finish.
Defense and turnovers dominated a first half in which there was just one touchdown, that coming on an 8-yard run by Mostert, giving the 49ers a 7-3 lead.
The 49ers outgained the Rams 348-308.
--Field Level Media