FOXBOROUGH, Mass. -- The San Francisco 49ers blew a 31-3 third-quarter lead but managed to pull out a wild 41-34 victory over the New England Patriots on Sunday night.
The win clinched an NFC playoff spot for the Niners (10-3-1), while the Patriots (10-4) saw their seven-game winning streak end.
The loss also New England's 20-game home December winning streak and a 13-game overall December winning streak.
After Colin Kaepernick threw three touchdown passes, one to ex-Patriot Randy Moss, to give the visitors a 28-point lead with 10:21 left in the third quarter on a cold, rainy night, Tom Brady brought the Patriots all the way back.
Danny Woodhead scored on two runs, and Brady scored on a fourth-down sneak and threw a 5-yard touchdown pass to Aaron Hernandez, Brady's 467th consecutive game with a TD pass.
After Woodhead tied the game with a 1-yard run with 6:43 left, it took the Niners, who have won four of their last five, 20 seconds to get the decisive touchdown.
LaMichael James ran the kickoff back 62 yards to the New England 38-yard line, and San Francisco scored on the next play. Kaepernick, now 4-1 as a starter, hit Michael Crabtree with a short pass, but Crabtree eluded Kyle Arrington and sprinted into the end zone for his second touchdown of the game.
Two penalties on late punts killed the Patriots, who turned the ball over four times to lose the turnover battle for the first time this season. After the second penalty, which pinned them on their 3-yard line, they failed on a fourth-and-2 from their 12, and the 49ers got a 28-yard field goal from David Akers with 1:56 left.
Brady then took his team down the field, and the Patriots elected to take a field goal, a 41-yarder by Stephen Gostkowski, on second down. The kick came with 38 seconds left. The Patriots then tried an onside kick, but the Niners recovered.
Kaepernick completed 14 of 25 passes for 216 yards, four TDs and an interception. Crabtree made seven receptions for 107 yards.
San Francisco's Frank Gore ran 21 times for 83 yards, and he recovered a fumble for a touchdown.
Brady finished 36-for-65 for 443 yards, one touchdown and two interceptions. New England's Wes Welker, who had five catches for 56 yards, became the first receiver in NFL history with five 100-catch seasons. Brandon Lloyd, in his second big game in a row after a tough rest of the season, caught 10 passes for 190 yards. Recently re-signed Deion Branch had four receptions for 37 yards.
The loss cost the Patriots a chance at their third straight perfect second half of the season. They had gone 8-0 in the second half of the last two seasons, and were 5-0 this year before the Sunday night defeat.
By all rights, the 49ers probably should have held a 24-0 lead by the early moments of the second quarter. Instead, thanks to a weird series of events in the rain, it was only 7-3 after Brady led his team to a 32-yard Gostkowski field goal with 8:31 left in the first half.
A New England lost fumble was overturned, but the Patriots punted on their first possession, and Kaepernick took his team down the field with completions of 11, 13, 12 and 24 yards, the latter a touchdown pass to Moss. With the scoring grab, his second catch of the game, Moss moved past Isaac Bruce into third place on the NFL's all-time receiving yardage list. Bruce finished with 15,208 yards.
Brady threw an interception later in the quarter but prevented Carlos Rogers from scoring by tackling him on the New England 5. Delanie Walker fumbled it right back to the Pats after a reception.
A fake punt (a 31-yard, direct-snap run by Dashon Goldson) put the Niners in position to score again, but David Akers missed a 39-yard field goal. A Shane Vereen fumble gave the ball right back to San Francisco, but the Niners failed on a fourth-down sneak (the third dropped snap of the game).
This time, Brady took his team to the field goal, but an obvious pass-interference call on Aqib Talib set the 49ers up again. This time, Kaepernick hit Walker with the 34-yard touchdown pass with 6:54 left in the half.
A lengthy delay followed a Zoltan Mesko punt later in the second quarter, as the officials correctly decided to leave the ball with the 49ers after San Francisco return man Ted Ginn didn't touch the ball. Taking over on their 22, the Niners marched down the field, with Kaepernick scrambling for 19 yards on a third-and-8 from the New England 34.
The ball got down to the Patriots' 4-yard line before an interference call on Moss in the end zone put it back to the 14. Kaepernick ran it back to the 4, and Gore gained 2 yards before Akers hit a 20-yard field goal to make it 17-3 at the break.
NOTES: New England converted just two of 15 third-down attempts. ... The Patriots wore stickers on their helmets and joined the rest of the NFL with a moment of silence to honor the people killed in Newtown, Conn. One flare was sent into the air for each of the 26 victims. ... Moss shook hands with Patriots owner Robert Kraft before the game. ... The Patriots visit Jacksonville next Sunday, while the 49ers play at Seattle. ... New England honored its five Hall of Famers -- John Hannah, Nick Buoniconti, Mike Haynes, Curtis Martin and Andre Tippett -- in conjunction with Canton's 50th anniversary. Martin, Haynes and Tippett were introduced before the game and joined the current captains for the coin toss. ... The teams met for the first time since 2008. ... Both teams were missing key receivers. Mario Manningham (shoulder) was out for the Niners, who lost Kyle Williams for the season Nov. 25. New England tight end Rob Gronkowski was sidelined due to a broken arm. Gronkowski returned to light practice leading up to the game, but he missed his fourth consecutive game.