SAN FRANCISCO -- Quarterback Alex Smith threw for 226 yards and two touchdowns, both to tight end Vernon Davis, leading the San Francisco 49ers to a 27-19 victory Sunday night over the Detroit Lions at Candlestick Park.
Smith's 23-yard touchdown pass to Davis with 3:04 left to play put the 49ers ahead 27-12. Detroit cut the lead to 27-19 on Matthew Stafford's 9-yard touchdown pass to tight end Brandon Pettigrew with 1:29 remaining.
San Francisco wide receiver Kyle Williams then recovered the Lions' onside kick.
The 49ers beat Detroit for the ninth straight time and 14th time in the past 15th meetings.
This was a rematch of a Week 6 game last year remembered most for an altercation between 49ers coach Jim Harbaugh and Lions coach Jim Schwartz after the final gun of San Francisco's 25-19 comeback win. Harbaugh gave Schwartz a hard handshake and a slap on the back that day, and Schwartz took exception.
This time, the two coaches met on the field before Sunday night's game for a friendly handshake and a brief chat. There were no postgame handshake fireworks.
Running back Frank Gore rushed for 89 yards and one touchdown on 17 carries for the 49ers. Davis caught five passes for 73 yards, and wide receiver Michael Crabtree had six receptions for 67 yards.
The 49ers' defense contained Stafford, wide receiver Calvin Johnson and Detroit's explosive passing attack for most of the night.
Stafford, who threw for 5,038 yards and 41 touchdowns last season, had 89 passing yards and no TDs through the first three quarters and finished with 230 yards and one scoring pass. Johnson caught 96 passes for 1,681 yards and 16 TDs last year. He had six catches for 46 yards and no scores entering the fourth. He finished with eight catches for 94 yards but no scores.
After building a 14-6 halftime lead, the 49ers took the opening kick in the second half and marched 62 yards for David Akers' 36-yard field goal, making it 17-6.
The Lions spent much of the first half trying to establish a running game against one of the NFL's top run defenses, and they kept trying in the third quarter. They marched methodically to the 49ers' 22 but stalled. Jason Hanson's 40-yard field goal cut the 49ers' lead to 17-9 with 3:40 left in the third.
The 49ers answered with Akers' 48-yarder with 14:42 to play, extending their lead to 20-9. Hanson's 48-yarder made it 20-12 with 9:16 left to play.
The 49ers forced a three-and-out on Detroit's game-opening possession then needed just four plays and 1:12 to drive 67 yards for a touchdown on Smith's 21-yard strike to tight end Davis.
After Smith threw an incompletion on first down, Mario Manningham gained 29 yards on an end- around, and Smith hit wide receiver Crabtree for 17 yards to the Lions' 21. On the next play, Davis ran past Lions safety John Wendling, and Smith hit him in stride in the back left corner of the end zone, giving the 49ers a 7-0 lead with 12:25 left in the first quarter.
Detroit countered with Jason Hanson's 38-yard field goal, cutting the 49ers' lead to 7-3. The Lions got the ball back when linebacker Tahir Whitehead caused 49ers kick returner Kendall Hunter to fumble, and Kassim Osgood recovered at San Francisco's 25. The 49ers had gone 26 straight quarters without a turnover before Hunter's fumble.
The Lions failed to get a first down and settled for Hanson's 41-yard field goal -- it bounced in off the right upright -- slicing the 49ers' lead to 7-6 with 6:43 left in the first half.
Late in the first quarter, 49ers safety Dashon Goldson made a diving interception of a Stafford overthrow and returned it 20 yards to the Detroit 23. It appeared the 49ers would have to settle for Akers' 35-yard field goal, but Lions cornerback Drayton Florence was flagged for running into the kicker. That gave the 49ers a first down at the 12. Two plays later, Lions cornerback Jacob Lacey was penalized for pass interference in the zone while covering Randy Moss.
Gore, who rushed for 61 yards on 10 carries in the first half, rammed into the end zone from a yard out, giving San Francisco a 14-6 lead with 14:57 left in the half.
Late in the half the Lions drove 65 yards but came away empty when Hanson's 40-yard field goal hit the right upright and bounced backward.
NOTES: The Lions came into the game short-handed in the secondary. Three of their four starters were out with injuries: cornerbacks Chris Houston (ankle) and Bill Bentley (concussion) and free safety Louis Delmas (knee). Florence and Lacey started at cornerback, while Wendling started at free safety. Florence signed with the Lions two weeks ago after being waived by Denver. Strong safety Erik Coleman was the only regular in the secondary who started. ... Rookie wide receiver A.J. Jenkins, the 49ers' first-round draft pick, was inactive. So was running back LaMichael James, San Francisco's second-rounder. ... Ted Ginn Jr., the 49ers' top return man, was out with an ankle injury.