San Francisco kept Detroit in the game with missed opportunities, then made just enough plays for a rare two-game winning streak and its first road win.
Keith Lewis intercepted Jon Kitna 's pass at the 49ers' 2 with 2½ minutes left and San Francisco (4-5) picked up the one first down it needed to seal the game, winning consecutive games for the second time since 2003.
"A lot of the talk for us this week was to create a streak and to win on the road, two things we haven't had," San Francisco coach Mike Nolan said. "I'd like to think it's a turning point."
The Lions (2-7) had a chance to win consecutive games for the first time in nearly 26 months and the third time since 2001, when Matt Millen took control of the franchise. Despite the lack of success, some players were bold enough to talk about winning four in a row after beating Atlanta by 16 points last week.
"Yes, it is a setback," said wide receiver Roy Williams, who has confidently talked about putting together an extended winning streak. "I think we came out a little flat. I don't think we were into this ballgame.
Gore finished with career-high 159 yards rushing, leaving the game when he stumbled to the sideline late in the third quarter after catching a pass.
"He got his bell rung," Nolan said. "It's a mild concussion."
"It was big," said Smith, who avoided a sack on the play before delivering a crisp pass on an out route. "It was nice that our coaches had the confidence to call that play with the game on the line."
Kitna was 19 of 30 for 202 yards with a touchdown, interception and fumble. Kevin Jones accounted for 115 yards rushing and receiving, and Williams was limited to 81 yards receiving.
The 49ers entered the game giving up an NFL-high 30 points a game -- and an average of 40 in their previous three road games -- but they shut down Detroit's Mike Martz-directed offense a week after limiting Minnesota to three points.
San Francisco led 13-3 at halftime after scoring on three of its first four drives, wishing it had a bigger lead after outgaining Detroit 247-102 and recovering a fumble without giving up a turnover.
"The feeling was we had done a lot better than the scoreboard showed," Smith said.
The 49ers had chances to go ahead big in the third quarter because Detroit had two turnovers on its first three plays, but they came away with only a field goal and a 13-point lead.
Smith's fumble midway through the third quarter set up a score that helped the Lions get back in the game. Kitna lofted an 8-yard pass to Dan Campbell to make it 16-10.
Gore then caught a 7-yard pass, wobbled off the field and didn't return. The 49ers drove down the field to set up Nedney's fourth field goal, a key score because it made Detroit go for a TD instead of kicking a tying field goal late in the game.
Jason Hanson made a field goal on the ensuing drive, making it 19-13 in a game marred by missed opportunities by both teams.
Gore started his day with a big run. On one of Gore's many draws, he squirted away from a few Lions on the left side and cut across the field for a 61-yard TD.
"I saw a lot of missed tackles," Nolan said.
San Francisco added to its cushion early in the second quarter with another field goal by Nedney two plays after Smith threw directly at cornerback Stanley Wilson, who likely would've scored had he simply caught the ball.
"There's really no excuse," Wilson said. "I've got to have that play for my team to help us win."
Detroit coach Rod Marinelli was disappointed in how his team began the game, lacking an emotional edge.
"I'm not a sugar-coater," Marinelli said. "I'm going to take the film and put it right in their faces. I'm not going to put it all on them -- we didn't teach them well enough -- but I'm going to tell them the truth."
Notes: Garrison Hearst had San Francisco's previous record for yards rushing in a half, with 136 yards against the New York Jets in 1998, when he set a franchise record with a 96-yard run. ... San Francisco S Mike Adams (neck) and OL Adam Snyder (left knee) were injured in the game, and Marinelli said the Lions came out of it healthy.