Jimmy Garoppolo threw for 206 yards and a pair of touchdowns as the 49ers tamed the Lions 30-27 in Santa Clara.
Garrett Celek and Kendrick Bourne were on the receiving end of the scores for San Francisco. Matt Breida finished with 138 rushing yards, including a 66-yard touchdown run in the winning effort.
The Niners improved to 1-and-1.
Detroit entered the fourth quarter in a 27-13 hole but a pair of Matthew Stafford touchdown passes pulled them within three.
Stafford threw for 347 yards and three scores as the Lions fell to 0-and-2.