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 another wrinkle into the NFC West.
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 of the San Francisco 49ers on Sunday.
''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.
''Jo-Lonn (Dunbar) did a great job recognizing sneak. You can just kind of tell by a quarterback's mannerisms when they're going to sneak.''
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 know I crossed the line. I was looking into the end zone,'' Kaepernick said.
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.
''We have to play good football in order to win in this league, there's no question about it,'' 49ers coach Jim Harbaugh said. ''Today was not good enough to win.''
Kenny Britt caught a 21-yard touchdown pass that tied the game at 10 just 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 Kaepernick and forced 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.
Rams coach Jeff Fisher considered the endings to either half among the strangest he has seen.
''We even had some bizarre stuff at the end of the first half, too, and that was a little unusual,'' he said.
Kaepernick threw a 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 went 13 for 24 for 105 yards and was quick to credit the defense for banged-up St. Louis, limited to a walk-through Wednesday because of injuries.
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.
''They deserve it,'' Davis said of the D. ''They won us the ballgame today.''
Notes: Rams DE Williams Hayes left with a second-half ankle injury, while San Francisco LB Dan Skuta (left ankle) and WR Brandon Lloyd (hamstring) also made early exits. ... Rookie 49ers LB Chris Borland had 18 tackles, 15 solo, playing in place of Willis.
AP NFL website: www.pro32.ap.org and www.twitter.com/AP-NFL