Alex Smith's fourth-down, 6-yard pass to Delanie Walker gave San Francisco the go-ahead touchdown with 1:51 left, lifting the 49ers to a 25-19 win over the previously unbeaten Detroit Lions.