Marc Bulger threw a 5-yard touchdown to Kevin Curtis with 27 seconds left to end a five-game skid.
The score came after the 49ers went 75 yards in 13 plays and 7:34, capped by Joe Nedney's 24-yard field goal. The drive ended when Michael Robinson was stopped on third and 1. Frank Gore, who had 134 yards, had left the game four plays earlier after rolling his right ankle. Coach Mike Nolan said it was a bruise but didn't disclose his status.
Bulger went 9-for-9 for 66 yards on the ensuing 12-play, 80-yard drive. Steven Jackson had two carries for 10 yards and four catches for 25 yards during the drive. He ran for 6 on fourth and 1 from the Rams 29 and 4 on fourth and 1 from the 49ers 13. Then after Bryant Young's delay of game, Bulger hit Curtis.
NOTABLE: St. Louis' Torry Holt had 30 receiving yards for 10,282 in his first eight seasons, a league record and 9 more than Jerry Rice.