The 49ers trailed 16-0 early. They trailed 26-23 with seconds remaining.
They won 36-26.
Running back Jeff Wilson scored on a 25-yard pass from Jimmy Garoppolo with 31 seconds remaining. It was the fifth lead change of the second half.
Garoppolo, who threw for 317 yards and a career-best four touchdowns two weeks ago against the Cardinals, had a career day with 424 yards, four touchdowns and two interceptions.
A sixth lead change was not in the cards as Arizona receiver KeeSean Johnson fumbled with 25 seconds remaining. Defensive lineman Damontre Moore, who signed with the 49ers this week, forced the fumble and Jaquiski Tartt recovered.
The Cardinals got two plays to end the game, and it resulted in cherry on top of the 49ers’ victory. D.J. Reed Jr. scooped up the loose ball, as the Cardinals tried to lateral their way to a win, and scored on a 4-yard return.
The last time the 49ers rallied from a deficit of 16 points or more in the regular season was Oct. 2, 2011, when they were down 23-3 to the Eagles before winning 24-23, according to Josh Dubow of the Associated Press.
The 49ers overcame a 17-0 deficit against the Falcons in the NFC Championship Game on Jan. 20, 2013.
The 49ers avoided a two-game losing streak in moving to 9-1, maintaining their lead over the Seahawks in the NFC West. The Cardinals fell to 3-7-1.
Kyler Murray passed for 146 yards and two touchdowns and ran for 67.
David Johnson played seven snaps in the first half, according to Josh Weinfuss of ESPN, none in the second half and did not get a touch. Kenyan Drake had 67 rushing yards and 13 receiving yards.