SANTA CLARA, Calif. (AP) -- James Laurinaitis and the St. Louis defense read Colin Kaepernick's mannerisms and were perfectly prepared for his quarterback sneak. The Rams stuffed him short and recovered his fumble, throwing the NFC West another wrinkle.
Kaepernick fumbled at the goal line with 2 seconds left trying for the go-ahead score, and the Rams sacked him eight times on the way to a 13-10 upset over the 49ers on Sunday.
The play was reviewed and upheld. If Kaepernick had maintained possession, the 49ers could have used their final timeout to try for the touchdown again, or attempt a field goal to tie.
"I just went to kind of meet him head to head down there and as I'm going down, I just see the ball sitting there," said Laurinaitis, who came out of the pile with the ball.
St. Louis is doing plenty to influence the West race, beating defending Super Bowl champion Seattle on Oct. 19 and the 49ers two weeks later - by a combined five points.
Greg Zuerlein kicked the go-ahead 39-yard field goal for the Rams (3-5) with 5:25 left, then San Francisco got another chance.
Kaepernick started the last drive with 3:11 remaining from the 49ers' 12. He completed long passes to Stevie Johnson and Anquan Boldin. Trumaine Johnson helped San Francisco get closer with back-to-back pass interference and holding penalties as he defended Michael Crabtree.
On third-and-goal from the 1, Kaepernick bobbled the snap, controlled it and dove between his blockers as fullback Bruce Miller tried to shove him into the end zone. Kaepernick fumbled as he went down in the mass of bodies, apparently short of the goal line.
"On the last play it went into a pile, and there was nothing we could see that could change the ruling on the field," referee Jerome Boger said.
The Rams, 9 1/2-point underdogs to start the week, never let Kaepernick get comfortable. The quarterback spent more time on his backside and running from St. Louis defenders than he did directing the offense.
Playing for the second time in 21 days, the teams both were coming off embarrassing routs - the Rams last week 34-7 in Kansas City and the 49ers 42-17 at Denver on Oct. 19 - and this wasn't pretty, either.
The Niners did little to impress members of the World Series champion San Francisco Giants in the stands wearing 49ers gear. Former coach George Seifert was in attendance as well for his induction into the franchise Hall of Fame.
"That was a tough loss. We didn't have enough good football to win the game," 49ers coach Jim Harbaugh said. "We got beat. We have to suck it up."
Kenny Britt caught a 21-yard touchdown pass that tied the game at 10 1:04 before halftime. Britt was wide open on a crossing route and easily ran in down the left sideline. That came three plays after Robert Quinn sacked forced Kaepernick into losing his first fumble of the day.
Then, the crazy final play of the first half was upheld on replay review.
When Phil Dawson's 55-yard field goal try came up well short, Tavon Austin caught the ball near the back of the end zone and brought it out a few yards before backtracking to try to get around the right edge.
Derek Carrier tackled Austin in the end zone as the first-half clock expired.
As the two teams headed for their respective locker rooms, the head coaches stayed put for the ruling, which was that forward progress was stopped in the field of play and the play stood without a safety.
Kaepernick threw an earlier 27-yard touchdown pass to Boldin, giving him TD passes in 15 straight games - tied for the second-longest streak in franchise history with Jeff Garcia. Hall of Famer Steve Young had 17 in a row.
When the NFC West rivals first played Oct. 13, Kaepernick threw for 343 yards and three touchdowns with no interceptions or sacks. He finished Sunday with 237 yards on 22-of-33 passing.
Rams quarterback Austin Davis had a scare in the first quarter. After a 10-yard, he slid on his braced left knee and it caught awkwardly in the loose sod that has been problematic at Levi's Stadium. Backup Shaun Hill entered for one play and Davis returned.
San Francisco struggled to get pressure on Davis, while missing star linebacker Patrick Willis for the second straight game with an injured left big toe.