Colin Kaepernick passed for 343 yards and three touchdowns as the San Francisco 49ers erased an early deficit en route to a 31-17 NFL victory over St. Louis.
San Francisco quarterback Kaepernick recorded the second-best passing performance of his career.
But things looked grim for the 49ers after the Rams leapt to an early 14-0 lead.
San Francisco responded by scoring 24 straight points, a run that included a game-changing touchdown at the end of the first half.
The 49ers trailed 14-3 with less than 30 seconds left in the first half when San Francisco Brandon Lloyd eluded Rams defender Janoris Jenkins and turned up the left sideline.
Kaepernick found him and Lloyd sprinted for an 80-yard touchdown.
Kaepernick also connected with Anquan Boldin and Michael Crabtree on touchdown passes as San Francisco won their third straight game.
It was Kaepernick’s first three-touchdown game since last November 25 at Washington.
San Francisco improved to 4-2, to lie second behind Arizona in the NFC West, while the Rams at 1-4 are in last place in the division.
The win may have been costly for San Francisco.
All-Pro linebacker Patrick Willis with a toe injury, rookie linebacker Jimmie Ward with a quadriceps injury and Pro Bowl guard Mike Iupati with a concussion all departed the game.
Rookie Dontae Johnson sealed the win with a 20-yard interception return for a touchdown with 53 seconds remaining.