Hartley drilled kicks from 21 and 42 yards in the fourth quarter, rallying the Saints from a 20-14 deficit, then added a 31-yarder on the game's last play.
Drew Brees threw for 305 yards with a touchdown and an interception for the NFC South-leading Saints (8-2), whose cause was helped by a controversial personal foul penalty on San Francisco's Ahmad Brooks.
On defense, New Orleans held the 49ers to just 196 total yards.
Colin Kaepernick could manage just 127 aerial yards for San Francisco (6-4).
NBC reportedly holds celebs hostage to Jimmy Fallon's show
Boston schools pull out free condoms over wrapping complaints