49ers quarterback Jimmy Garoppolo threw for 317 yards and four touchdowns in beating the Arizona Cardinals 28-25 on Thursday night.
With the win, San Francisco remains unbeaten and improves to 8-and-0 on the season.
The 49ers actually fell behind 7-0 in the game but responded with three touchdowns including one as time expired in the second quarter. That touchdown came after Cardinals coach Kliff Kingsbury called a timeout and gave the 49ers a second chance on fourth down, giving them a 21-7 halftime lead.
Arizona staged a comeback with five minutes left in the fourth quarter, when Andy Isabella caught a short pass and sprinted 88 yards to help the Cardinals pull to 28-25.
But the 49ers were able to run out the clock on their ensuing offensive drive.
Rookie quarterback Kyler Murray threw for 241 yards and two touchdowns as Arizona drops to 3-5-and-1 on the season.
The New England Patriots are the NFL's only other unbeaten team at 8-and-0.
With files from the Canadian Press