FOXBOROUGH, Mass. -- The 49ers clinched a playoff berth Sunday night in one of the most incomprehensible games in NFL history, all while upsetting the host New England Patriots 41-34.
Amid rainy conditions and in a turnover-filled game, the 49ers (10-3-1) saw a 31-3 lead vanish as the Tom Brady-led Patriots (10-4) pulled even at 31-31 with 6 minutes, 43 seconds remaining.
This prime-time classic didn't stay tied long, however. Rookie LaMichael James responded with a 62-yard kickoff return, and as the 49ers huddled up at the Patriots' 38-yard line, quarterback Colin Kaepernick told his teammates: "We need to score this drive."
The game-winning drive took one snap: Kaepernick delivered his career-best fourth touchdown pass, with Michael Crabtree making a 38-yard catch-and-run for a finally insurmountable 38-31 lead.
"Great victory," 49ers coach Jim Harbaugh said. "Loved the way our team sucked it up so many times. We didn't make all the plays. ... But we made more than them."
The 49ers can lock up their second straight NFC West title -- or jeopardize that quest -- with next Sunday night's visit to the second-place Seattle Seahawks (9-5). The 49ers remain a half-game ahead of the Green Bay Packers (10-4) for the NFC's second-best record. The Atlanta Falcons (12-2) have clinched the NFC South title and at least a first-round bye.
Only the 1980 49ers had come back from a 28-point deficit to win a regular-season game, doing so against the New Orleans Saints behind second-year quarterback Joe Montana.
The AFC East-champion Patriots hadn't lost in their past 20 December home games, and they sure didn't go quietly Sunday night.
"I love it," 49ers right tackle Anthony Davis said. "To do this in their house, it doesn't get better than that."
The Patriots' fate was basically sealed when Brady's third- and fourth-down passes failed to find Danny Woodhead, giving the 49ers possession at the Patriots' 12-yard line with 2:20 remaining.
"It was a big relief to stop them. They were hot," said linebacker NaVorro Bowman, who covered Woodhead on both incompletions.
The 49ers converted their ensuing possession into a 28-yard field goal by David Akers, and the Patriots could only respond with Stephen Gostkowski's 41-yard field goal with 38 seconds left. Delanie Walker recovered the ensuing onside kick to finalize the victory.
No score proved bigger than Crabtree's second touchdown catch, the one that put the 49ers back on top 38-31 on their first snap after the Patriots' tying drive.
"I told Kap to put the ball up, he did and I took off running," Crabtree said. "Kap trusted me, and we made it happen."
It happened in the face of an all-out blitz, which was quickly spotted by Kaepernick, a second-year whiz kid making his fifth consecutive start.
"It was not where he was supposed to go with the ball. It wasn't the intent," Harbaugh said of the play call. "But he saw what he saw and kicked it back to Michael."
"I liked that matchup, and Crab made a great play," said Kaepernick, who was 14 of 25 for 216 yards. He also ran seven times for 28 yards and was sacked once.
The 49ers hadn't scored since Kaepernick third's touchdown pass -- a 27-yard strike to Crabtree -- provided a 31-3 lead with 10:21 left in the third quarter. That score came one snap after 49ers linebacker Aldon Smith recorded his first career interception.
But Brady responded by leading four touchdown drives, capped by two Woodhead runs, a 1-yard Brady sneak and a 5-yard pass from Brady to Aaron Hernandez.
"Yeah, it was really good, Tom Brady-like," Harbaugh said of Brady's second-half form. "Nobody else to compare it to."
Crabtree added: "Hats off to the (49ers) defense for stopping my dude, Tom Brady. He's one of my favorites."
Brady's comeback powers amazingly offset the earlier success of the 49ers defense, which forced a season-high four turnovers in an eight-series span.
"We made way too many mistakes when we needed to make plays," said Brady, who finished 36 of 65 for 443 yards with one touchdown and two interceptions.
The cold, rainy conditions impacted the 49ers' offense, too, but without such dire consequences. Kaepernick didn't lose any of his four fumbles, the last of which Frank Gore recovered for a 9-yard touchdown run and a 24-3 lead.
Walker made a 34-yard touchdown catch to put the 49ers ahead 14-3, and the Gillette Stadium crowd became quieter than a closed library. That was the second touchdown pass by Kaepernick, who celebrated by "Kaepernicking" and kissing the tattoos on his right biceps.
"I told everybody from the beginning, 'Kap is good. He's the truth,' " Aldon Smith said. "The kid's good. Accept it and keep expecting good things from him."
Smith was held without a sack for the first time in eight games. He and the 49ers defense also had to make do in the fourth quarter without mainstay lineman Justin Smith, who sustained an elbow injury that will require an MRI on Monday.
Clinching a playoff berth was part of Harbaugh's pregame message, and it didn't go overlooked afterward.
"It feels great to get a win, and it helps us move forward on where we want to be in the playoffs," Kaepernick said.
Added Aldon Smith: "That's what where we want to be, to get back to the playoffs and get in position to get to New Orleans (for Super Bowl XLVII)."
49ers (10-3-1) at Seattle (9-5), 5:20 p.m. NBC
More 49ers coverage
Rookie LaMichael James comes through with big kickoff return. Page 7
Burned by Tom Brady, 49ers defense recovers to make a late stand. Page 7