FOXBORO, Mass. -- The 49ers were well on their way to a rout of the favored New England Patriots on Sunday night.
And, then, their world quickly came apart at the seams.
But a 28-point cushion was all the 49ers lost. After seeing their four-touchdown lead vanish into the freezing drizzle at Gillette Stadium, the 49ers did not completely fall apart.
"We're a fighting team and we'll play for 60 minutes," 49ers linebacker Patrick Willis said.
The 49ers clinched a spot in the NFC playoffs with an improbable 41-34 victory over the Patriots that had a little bit of everything.
And just when it looked its most bleak for the 49ers, second-round draft pick LaMichael James provided his first big moment with the team.
With the 49ers' 31-3 lead suddenly gone, James, who was inactive for the 49ers' first 12 games of the season, went back deep to receive the kickoff with 6:43 remaining with the score tied.
Did any of his teammates say anything before the kickoff return?
"Everyone said something," James said.
The 49ers needed a boost. Everybody knew the 49ers were in danger of one of the great collapses in NFL history. And James supplied a huge momentum swing with a 62-yard kickoff return. Delanie Walker told James to follow him, and that's exactly what James did, as he tip-toed the left sideline.
"One play doesn't win a game, but I think it put us in good position to get the score," James said. "It was a game-changing play, and it helped us win."
The go-ahead touchdown came on the next play, as quarterback Colin Kaepernick and Michael Crabtree improvised on a 38-yard touchdown, which came on a long run after a 5-yard hitch.
"(It) was a nice job by Colin," 49ers coach Jim Harbaugh said. "(It's) not where he was supposed to go with the ball. It wasn't the intent of the play. But he saw what he saw, kicked it out to Michael and then Michael made a huge play."
Why did Kaepernick make that throw?
"I liked the matchup," Kaepernick said.
The Patriots came with an all-out blitz, and Kaepernick got the ball out quickly to Crabtree, who broke the tackle attempt of cornerback Kyle Arrington and then beat safety Devin McCourty into the end zone.
Kaepernick, making his fifth NFL start, completed 14 of 25 passes for 216 yards with four touchdown passes and one interception. His passer rating was 107.7. Crabtree caught seven passes for 107 yards and two touchdowns. It was the most points the 49ers have scored in a road game since a 45-17 victory over the San Diego Chargers on Dec. 3, 2000.
The 49ers overcame four Kaepernick fumbled snaps (none of which was lost), a missed field goal and two turnovers to foil prime scoring chances. The 49ers generated four turnovers against the Patriots, who turned the ball over just 10 times in their first 13 games.
The 49ers (10-3-1) wrapped up a spot in the NFC playoffs with the victory. They can clinch their second straight NFC West title with one win in their final two games -- at the Seattle Seahawks or against the Arizona Cardinals.
New England entered the game with a seven-game win streak and a string of 20 consecutive home victories in December.
"Great victory," Harbaugh said. "I really liked how our team sucked it up so many times. We didn't make all the plays, buy we made a lot of plays. It will be a happy flight home."
Patriots quarterback Tom Brady, who had just 76 yards passing at halftime, spearheaded a rally that saw New England score touchdowns of consecutive drives of 73, 86, 66 and 92 yards.
Brady finished with 36 completions in 65 attempts for 443 yards with one touchdown and two interceptions.
Kaepernick managed to hold it all together after the Patriots rallied to tie the score. Kaepernick fumbled four exchanges from center Jonathan Goodwin, including one on a failed fourth-down quarterback sneak attempt, prompting him to wear a glove on his non-throwing hand to get a better grip, he said.
Kaepernick threw an interception on a deep pass in the end zone to end the 49ers' first drive of the third quarter. But the 49ers got the ball back on Dashon Goldson's 66-yard fumble return. On the next play, Kaepernick fumbled the snap, but running back Frank Gore picked it up and scored on a 9-yard fumble recovery.
After 49ers outside linebacker Aldon Smith intercepted Brady on the next drive, Kaepernick hit Crabtree on a 27-yard touchdown for a 31-3 lead.
"I just feel this in my bones, after you throw an interception, it's very hard to lead a touchdown drive the next possession," Harbaugh said. "Basically, step back in there, throw the ball right down the middle, which he had done in a previous possession, and had it intercepted. It takes some gravel in your guts to do that. I think it says a lot."
Said Kaepernick, "We were just trying to stay calm about it. I kept talking to our offense, saying we have to keep putting up points. We're going to have to score at some point, especially the way they were putting up points."
In a game of wild and prolonged momentum swings, the 49ers could never feel completely secure with the victory until Walker recovered Stephen Gostowski's onside kick with :38 seconds remaining. Walker himself had a fumble deep in Patriots territory in the first half and caught a 34-yard touchdown in the second quarter.
"If we had any doubters before this," Walker said, "I don't think we have doubters now."