Vernon Davis tied the NFL record for touchdown receptions by a tight end with his 13th of the season, sparking the 49ers' late surge in a 28-6 victory on Sunday.
"Well, my number was called and coach told me if there was a DB out there, do what you do best and just run by him," Davis said. "That's what I did, I just ran as fast as I could."
Frank Gore added 107 yards rushing on 23 carries and two TDs for the 49ers (8-8), who pulled away after a desultory first half in which they mustered only 52 yards and trailed 3-0.
"This is not the style of game we wanted to have," coach Mike Singletary said. "This is not the way we wanted it to go. I'm thankful we were able to come out of this game, get the heck out here, get the heck out of St. Louis with a win."
San Francisco ended a string of six consecutive losing seasons, halted a six-game road losing streak and finished 5-1 against the NFC West. The Rams (1-15) wrapped up their first winless home schedule since going 0-6 in 1959 and only the third in franchise history.
The Rams needed a loss in the finale to secure the No. 1 pick for the first time since 1997, when they traded up to get seven-time Pro Bowl tackle Orlando Pace. Their puny offense filled the bill with 109 yards total offense, fifth-worst in franchise history and lowest since they had 105 yards on Sept. 8, 1996, at San Francisco.
Steven Jackson had 63 yards rushing on 20 carries for the Rams, whose biggest play was a 56-yard punt return by Danny Amendola to the San Francisco 19 that led to a field goal that cut the 49ers' lead to 7-6 with 9:11 to go.
"We have a lot of things that need to get turned around," Jackson said. "Something has to turn."
It's the first No. 1 overall pick they earned since taking Oregon State quarterback Terry Baker, the Heisman Trophy winner the previous season in 1963. So there'll be some excitement as the rebuilding continues in the offseason for the Rams, who picked second overall the previous two seasons and are 6-42 the past three seasons.
"I'm not going to deny that one," coach Steve Spagnuolo said.
The 49ers held an opponent to 10 or fewer points for the seventh time behind a season-high eight sacks including 3 1/2 by Justin Smith, who entered the game with 2 1/2 sacks.
Rams rookie quarterback Keith Null was 7 for 17 for 57 yards and absorbed five of the sacks before sustaining a possible concussion in the third quarter. Spagnuolo said wide receiver Donnie Avery sustained a concussion and said Null "was fuzzy as well," but added, "I don't know if they used the term concussion."
Davis tied the mark set by Antonio Gates last season with the longest catch of his career, getting behind the defense on a 73-yard reception from Alex Smith that put the 49ers ahead 14-6 midway through the fourth quarter.
Gore had four 100-yard games in the last five games, and five overall.
The Rams were blacked out on local television for the third straight game and attendance at those games are the three lowest since the franchise relocated to the Midwest in 1995.
Paid attendance of 47,965 was the best of the three, likely boosted on "fan appreciation day" that featured multiple giveaways of flat-screen TVs, game-worn jerseys and Super Bowl tickets along with greatly reduced prices for concessions and team store merchandise.
Josh Brown's 54-yard field goal in the second quarter, a yard off his season best, was the only scoring in the first half. Brown was wide left on a 45-yard attempt to end the half after the Rams declined to use any of their timeouts.
The Rams ran out of offensive guards when rookie Roger Allen III, making his first career start after being undrafted out of Division II Missouri Western, injured his left knee in the second quarter. The flip card listed Mark Setterstrom, out for the season with a left triceps injury that will require surgery, as the backup at two positions, while starting tackle Adam Goldberg was listed as the backup at two positions.
The 49ers allowed only eight sacks the last six games, including two in the finale. ... Rams DE Chris Long was ejected late in the fourth quarter after a head butt. ... 49ers wide receiver Isaac Bruce got a ceremonial start in what likely was his final NFL game in the city where he was a four-time Pro Bowler. Bruce played one snap, jumped and bumped with a teammate and then spent the rest of the game watching from the sideline.
Several Buffalo Bills players accused star receiver Odell Beckham Jr. of throwing punches after plays late in the New York Giants' 24-10 win in Buffalo.
Colts quarterback Andrew Luck threw and took the majority of the snaps in practice Tuesday, giving the indication that he is on track to play in Thursday's game against the Texans.
New York Attorney General Eric Schneiderman has launched an inquiry into DraftKings and FanDuel to look into possible advantages daily fantasy employees might have gained by exploiting data.
For the first time since signing with Dallas in March, defensive end Greg Hardy spoke at length Tuesday, but not about the domestic violence incident that led to his suspension.
Lions coach Jim Caldwell said Tuesday he is instructing his players not to talk about the batted ball controversy that happened at the end of Monday night's loss to Seattle.
Lance Easley, the referee who made the infamous "Fail Mary" call in 2012, plans to contact back judge Gregory Wilson about Monday's controversial call to offer support.