Colin Kaepernick threw for 343 yards and three touchdowns, and the San Francisco 49ers beat the Rams, 31-17, in St. Louis on Monday night. The Rams led 14-0 after one quarter, but the 49ers rallied to capture the victory.

Kaepernick began the comeback with an 80-yard TD pass to Brandon Lloyd with just 14 seconds left in the first half. The touchdown brought San Francisco (4-2) within 14-10 at intermission.

Kaepernick then threw scoring strikes to Anquan Boldin and Michael Crabtree in the third quarter, as the 49ers moved past St. Louis (1-4) on the way to a big NFC West win.

After a Greg Zuerlein field goal pulled the Rams within 24-17, Dontae Johnson sealed the 'Niners victory with a 20-yard interception return for a touchdown with 53 seconds to play.