The 49ers scored twice within a minute in the final frame -- once when Smith found Vernon Davis on a 31-yard scoring strike for a 20-13 lead, and again on Kendall Hunter's 17-yard TD run following a Carlos Rogers interception.
New York's Eli Manning found Hakeem Nicks on a 32-yard TD reception midway through the fourth and was driving for the tying score with time winding down, but defensive end Justin Smith batted down his fourth-down pass at the 10-yard line to preserve the 49ers' win.
San Francisco (8-1) reeled off a seventh straight victory for the first time since an 11-game streak in 1997.
Manning went 26-of-40 for 311 yards, two TDs and two interceptions for the Giants (6-3).
Ohio crash that killed two caught on camera [VIDEO]
Couple calls 9-1-1 over missing hash browns; assault McDonanld's employees