AP Sports Writer
FOXBOROUGH, Mass. (AP) -- Colin Kaepernick threw three touchdown passes and the San Francisco 49ers led the turnover-prone New England Patriots 31-17 early in the fourth quarter on a rainy Sunday night.
Six days after the Patriots' 42-14 win over the Houston Texans, who had the NFL's best record, they were on the other end in another game against one of the league's top teams.
Kaepernick, making his fifth start after replacing Alex Smith as San Francisco's starting quarterback, threw scoring passes of 24 yards to Randy Moss, 34 yards to Delanie Walker and 27 yards to Michael Crabtree.
The game was going so well for the 49ers that they even scored after Kaepernick fumbled on first-and-goal at the Patriots 3 after a 66-yard fumble return by Dashon Goldson. Frank Gore got the loose ball and ran 3 yards for the touchdown.
The Patriots turned the ball over again on the second play of the next series when Tom Brady threw his second interception of the game and just his seventh of the year. Aldon Smith got it, setting the 49ers up at the Patriots 27. Kaepernick hit Crabtree on the next play for a touchdown as the 49ers went ahead 31-3 with 10:21 left in the third quarter.
The Patriots had committed four turnovers to that point after entering the game with an NFL-low 10.
Danny Woodhead scored on a 6-yard run with just under six minutes left in the third, and New England closed to 31-17 when Brady scored on a 1-yard sneak on the first play of the final period.
The 49ers (9-3-1) would clinch a playoff berth with a victory. They lead the NFC West over the second-place Seattle Seahawks (9-5), who beat the Buffalo Bills 50-17 in Toronto earlier in the day.
The Patriots (10-3) have clinched the AFC East title and are going for home-field advantage throughout the conference playoffs. They trail Houston (12-2) for best record in the AFC. The Texans clinched the AFC South on Sunday with a 29-17 win over the Indianapolis Colts.
The Patriots have won their last 20 December games at home since losing on Dec. 22, 2002.
New England entered the game ranked first in the NFL in points scored and yards gained but struggled against a 49ers defense that has allowed the fewest points and second fewest yards in the league.
The Patriots were held to a 32-yard field goal by Stephen Gostkowski in their lowest halftime output of the season. They had six points at intermission during a 20-18 loss to the Arizona Cardinals in the second game of the season.
Moss, who scored 23 touchdowns with the Patriots in 2007, filled in for starting wide receiver Mario Manningham, who missed his second game with a right shoulder injury. Moss got behind Alfonzo Dennard and made the touchdown catch in the left side of the end zone. The grab moved him into third place in NFL history with 15,219 yards receiving, passing Isaac Bruce's 15,208.
Kaepernick wasted no time moving the ball through the air. His first three plays all resulted in first downs -- completions of 11 and 13 to Crabtree and 12 yards to Moss. Frank Gore then ran for 3 yards and, after an incompletion, Kaepernick hit Moss for the TD.
The 49ers outgained the Patriots 249 yards to 113 in the first half. New England struggled on its first five series with three punts, an interception and a lost fumble before Gostkowski cut the lead to 7-3 with 8:31 left in the second quarter.
The 49ers needed just three plays -- plus a 35-yard defensive pass interference call -- to respond. After the penalty gave them a first down at the Patriots 45, Gore ran twice for 8 and 3 yards before Kaepernick hit Walker in the right side of the end zone with Dennard covering,
San Francisco added a 20-yard field goal by David Akers on the last play of the half.
The game was slowed by officiating confusion that led to several lengthy conferences, including a delay of about 10 minutes while deciding whether 49ers punt returner Ted Ginn Jr., muffed a second-quarter kick. Officials ruled he didn't touch the ball and the 49ers got possession.
In the first quarter, Brady was hit twice by NFL sacks leader Smith while trying to pass, then was intercepted by Carlos Rogers when he overthrew Wes Welker. Rogers returned the interception 53 yards to the Patriots 5, where he was tackled by Brady.
But on the second play, Walker fumbled after a 1-yard catch and Aqib Talib recovered for the Patriots. They couldn't get a first down and punted.
After three plays, the 49ers set up to punt but faked as Goldson took the snap and ran 31 yards to the New England 28. Again, the 49ers failed to capitalize as Akers' 39-yard field goal went wide to the left with 2:14 left in the quarter.
Online: http://pro32.ap.org/poll and http://twitter.com/AP_NFL
Copyright 2012 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.