Frank Gore ran for 5- and 1-yard touchdowns for the 49ers (3-7).
The Rams' Marc Bulger completed 34-of-53 tosses for 295 yards and a touchdown, but was intercepted twice.
Antonio Pittman rushed 14 times for 95 yards for St. Louis (2-8), which has lost four in a row.
The Rams' Dave Looker caught a touchdown pass and Josh Brown made three field goals.
Campus cop fatally shoots Texas student during traffic stop
Puzzle-maker slips 'Murdoch Is Evil' into Rupert Murdoch's Sunday Telegraph