Garoppolo connected with Wilson over the middle for the go-ahead score one play after the Niners (9-1) narrowly converted on a third-and-3 pass that went to replay review.
Instead of being ruled short and having to decide whether to kick a tying field goal or go for it on fourth down, San Francisco had a new set of downs and took advantage on Wilson's first career touchdown catch.
David Johnson fumbled on the next play for the Cardinals (3-7-1), who squandered a 16-0 lead and lost their fourth straight game. San Francisco added a fumble recovery for a touchdown by D.J. Reed on the final play after a botched lateral by Arizona.
This marked the biggest deficit erased by the 49ers in a win since rallying from 20 points down to beat Philadelphia on Oct. 2, 2011. San Francisco also overcame a 17-point deficit in the NFC title game at Atlanta following the 2012 season.
Garoppolo threw for 425 yards and four touchdowns, but also threw two interceptions deep in Arizona territory that nearly doomed the 49ers. The first set up a field goal that put Arizona up 19-17 and the second came with San Francisco trailing by three late in the fourth quarter.
Jimmy Garoppolo having a career day. 422 yards and 4 TD. And I started him in fantasy football this week, perhaps most importantly.— Casey Pratt (@CaseyPrattABC7) November 18, 2019
The defense responded by forcing a three-and-out on a sack by Arik Armstead. Garoppolo then went 6 of 7 for 58 yards on the game-winning drive.
Kyler Murray threw two TD passes and put the Cardinals ahead 26-23 on a 22-yard keeper with 6:30 to play but it wasn't enough to beat the 49ers.
The Cardinals scored on their first two drives to take a 9-0 lead when Murray found Larry Fitzgerald all alone for a 5-yard score that was his 19th career touchdown against San Francisco.
Arizona added to the lead in the second quarter on a 5-yard TD pass from Murray to Pharoh Cooper before the Niners mostly abandoned an ineffective running game to get back into the contest thanks to a series of underneath passes.
Richie James Jr. took a screen 57 yards to set up Garoppolo's first of two TD passes to backup tight end Ross Dwelley. San Francisco settled for a field goal at the end of the half before Garoppolo and Dwelley connected again on the opening drive of the third quarter to put the Niners up 17-16.
San Francisco looked poised to add to that lead with a drive down to the 12 before Garoppolo threw an interception right to linebacker Jordan Hicks, whose 48-yard return set up a go-ahead field goal by Zane Gonzalez.
49ers DE Dee Ford left in the first half with a hamstring injury.
The Cardinals won a rare challenge of a pass interference call set up an early score. Coach Kliff Kingsbury challenged a no-call on a deep pass to Christian Kirk and had it overturned to pass interference on Richard Sherman. The 41-yard penalty turned a fourth-and-7 into a first-and-goal from the 3.
The Cardinals had to settle for a field goal after an offensive pass interference on Christian Kirk wiped out an apparent TD pass to Charles Clay.
Sherman, who hadn't been penalized since the season opener, was called for two more pass interferences against Kirk in the first half.
Cardinals: Week off before hosting the Los Angeles Rams on Dec. 1.
49ers: Host Green Bay on Sunday.
Go here for the latest news about the San Francisco 49ers.