FOXBOROUGH, Mass. With just under three minutes remaining Sunday, the league's No. 1 scoring offense needed a touchdown against the No. 1 scoring defense.
The defense won.
The 49ers held Tom Brady and the Patriots to a four-and-out deep in their own territory, leading to a short David Akers field goal that ended up being the game-sealing score in a wild and wet 41-34 victory that saw San Francisco fail to hold a 28-point lead in the third quarter and then get it back again at the end.
With the win, the 49ers guaranteed themselves a spot in the playoffs. If they beat the Seahawks blowout winners against Buffalo on Sunday next week in Seattle, they will win the NFC West for the second straight season.
"It's not the playoffs, but it was a playoff environment," cornerback Carlos Rogers said. "We know the next couple of games are going to be like that."
For most of the night, the storyline was the way Colin Kaepernick, making his fifth career start, outplayed veteran and NFL poster boy Brady. Kaepernick finished with four touchdown passes, including a 38-yard catch and run by Michael Crabtree late in the fourth quarter that recaptured the lead and put the 49ers ahead for good.
That score was set up by a 62-yard kickoff return by rookie LaMichael James, which may have been the game's most pivotal play.
"He did a great job staying in bounds, it looked like from my perspective," 49ers coach Jim Harbaugh said. "Huge run. Huge play of the game."
Brady threw two interceptions after being picked off only four times in the first 14 games.
Still, Brady engineered a furious comeback during the fourth quarter that saw the Patriots tie the score 31-31 with 6:43 remaining.
Brady threw 40 more passes than Kaepernick and finished with 443 yards. But the 49ers held him to a pedestrian 68.9 passer rating, and their nickel defense gave the Patriots quarterback fits throughout the game.
"I knew he attempted a lot (of passes)," Rogers said. "Once they got behind, we knew it was going to be seven-on-seven the rest of the game. We knew we just had to man up and stop them."
The Patriots had only 10 turnovers through the first 14 games but had four Sunday as the 49ers' defense ripped, tipped and yanked away the ball during the first half and third quarter.
Rogers came down with Brady's first-quarter bomb intended for Wes Welker and returned it 53 yards to New England's 5-yard line. Rogers tied for the team lead in interceptions last year with safety Dashon Goldson but hadn't had any this season before Sunday.
Aldon Smith, who is now tied for the lead league in sacks with Houston's J.J. Watt, had no sacks. But he did hit Brady two times and came up with a tipped pass for an interception in the third quarter. The 49ers scored on the next play, a 27-yard pass from Kaepernick to Crabtree.
The 49ers also forced Patriots running backs to fumble twice, once on a hit by NaVorro Bowman, the other by Donte Whitner. Goldson returned the Whitner-forced fumble 66 yards to the Patriots' 3.
The 49ers played without the anchor of their defensive line, Justin Smith, throughout much of the second half. Smith injured his elbow in the third quarter as Brady and the Patriots began their comeback.
His primary backup, Demarcus Dobbs, was placed on injured reserve last week. Instead Ricky Jean Francois filled in and ended up getting one of the three sacks on Brady. Defensive end Ray McDonald had the other.
After the game, Harbaugh likened the way the 49ers responded to a big, prime-time challenge to his childhood growing up near a railroad station. If you play in enough momentous games, Harbaugh said, they won't faze you.
"The more you hear the train," he said, "the less you hear it."