FOXBOROUGH (AP) — LaMichael James awaited the kickoff, determined to regain the momentum for the 49ers after they quickly lost all of a 28-point lead.
"We need a boost," he said. "That's what I was thinking. I was thinking I got to take it to the house."
He didn't get all the way there, but close enough to set up the decisive touchdown — going 62 yards before Colin Kaepernick's 38-yard pass to Michael Crabtree with 6:25 left — that helped San Francisco reach the playoffs with a 41-34 win over the New England Patriots on Sunday night.
"We faced adversity," James said. "Nobody flinched."
Now the 49ers have at least a wild-card berth with a 10-3-1 record, knowing a win against division rival Seattle (9-5) next Sunday clinches the AFC West title.
The Patriots (10-4) already had locked up first place in the AFC East with a chance to improve their chances for a first-round bye. They began the day in second place in the race for the two byes but fell behind the Denver Broncos (11-3). The Houston Texans (12-2) hold the top spot.
"We haven't thought about that yet," Tom Brady said. "What's in our control is winning football games."
Doing that on Sunday night seemed almost impossible after the 49ers rolled to a 31-3 lead on Kaepernick's 27-yard touchdown pass to Crabtree five minutes into the third quarter. Only one team in NFL history had won a regular-season game after trailing by 28 — a 38-35 win by the 49ers over the New Orleans Saints on Dec. 7, 1980.
But with 25 minutes left and Brady at quarterback, the 49ers weren't comfortable.
"Tom is a good quarterback and we knew some adversity was going to come and they were going to make plays sooner or later," linebacker NaVorro Bowman said.
They did — time after time — until they had tied the score at 31 on Danny Woodhead's second touchdown, a 1-yard run with 6:43 remaining.
Woodhead began the comeback with a 6-yard touchdown run, Brady scored on a 1-yard sneak on the first play of the fourth quarter and then threw a 5-yard touchdown pass to Aaron Hernandez less than three minutes later. And when Woodhead scored again, the Patriots had their fourth touchdown in 14 minutes, 16 seconds.
But two plays later — James' kickoff return and Crabtree's catch — the 49ers were back on top. And this time they stayed there.
David Akers made it 41-31 with a 28-yard field goal with 1:56 to go, Stephen Gostkowski kicked a 41-yarder for New England with 38 seconds remaining and San Francisco sealed the win when Delanie Walker caught the onside kick.
"We just spotted them 28 points," Brady said. "We fought hard, but you can't play poorly against a good team and expect to win. We can't miss plays that we have opportunities with."
For Kaepernick, a second-year pro starting just his fifth game, it was a chance to remain calm even as the big lead disappeared. He finished with 14 completions in 25 attempts for 216 yards and a career-high four touchdowns.
"This is my 17th year of football," he said. "I've been playing since I was eight years old. So, to me, I am going to go out there and I'm going to throw to the guy who is open and you try to keep football simple so your mind can be clear when you're on the field."
It was clear enough for him to throw a short pass to Crabtree then watch him race by cornerback Kyle Arrington for the go-ahead touchdown. That gave the team that had allowed the fewest points this season enough to beat the team that had scored the most.
"We can win a shootout," said Crabtree, who had 107 yards receiving. "Whatever it takes, that's our motto. ... We feel like we can do anything, sky's the limit."
New England, which had won seven straight games, lost for the first time at home in December in 21 games. The Patriots also had won 21 in a row in the second half of the schedule before San Francisco somehow regrouped late in a game it seemingly had clinched long before.
The 49ers forced four turnovers, matching the number of giveaways the Patriots had at home all season.
"I don't think they faced a physical defense like us all season," said San Francisco cornerback Carlos Rogers, who intercepted Brady midway through the first quarter and ran 53 yards to the Patriots 5.
The 49ers were leading 7-0 at the time on Kaepernick's 24-yard touchdown pass to former Patriot Randy Moss. Gostkowski's 32-yard field goal made it 7-3, but San Francisco scored on Kaepernick's 34-yard pass to Walker and David Akers' 20-yard field goal for a 17-3 lead at intermission.
"Everything" went wrong in the first half, Patriots wide receiver Wes Welker said. "A lot of bad football."
Frank Gore then recovered Kaepernick's fumble and ran 9 yards for a touchdown. Two plays later, Aldon Smith intercepted Brady's pass and Kaepernick struck on the next play with his 27-yard pass to Crabtree for a 31-3 lead with 10:21 remaining in the third quarter.
Still plenty of time for Brady.
"I had a feeling we'd be able to come back," he said.
But when the Patriots tied it, a poor job by the kickoff team proved costly.
"I did as much as I could to help the team win," James said.
It was just enough.
NOTES: The 49ers allowed 520 yards after entering the game second in the NFL in fewest yards allowed, 275.5 per game. ... Welker had five catches, giving him 100 and making him the first player in NFL history with that many in five seasons. ... Gore led all rushers with 83 yards on 21 carries. ... Brady was 36 for a career-high 65 for 443 yards, one touchdown and two interceptions.
Online: http://pro32.ap.org/poll and http://twitter.com/AP_NFL