SANTA CLARA, Calif. (AP) Jimmy Garoppolo felt the rush coming, lofted up a pass to Jeff Wilson Jr. and then let the crowd tell him everything else.

After a sometimes trying day that featured a big early deficit, two interceptions deep in Arizona territory and some big plays from Kyler Murray, Garoppolo delivered when it mattered most for the San Francisco 49ers.

Garoppolo threw a 25-yard touchdown pass to Wilson with 31 seconds left for his fourth TD pass of the game and the 49ers rallied from 16 points down for a 36-26 victory over the Arizona Cardinals on Sunday.

''I felt the pressure up the middle and I kind of put it out there and wanted him to just make a play on it,'' Garoppolo said. ''I just heard the crowd. I didn't even see him catch it.''

The key play for the go-ahead score came 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 facing a fourth-down decision in a three-point game, San Francisco had a new set of downs.

Wilson entered for his first offensive play of the game and beat edge rusher Chandler Jones, who peeled off on a blitz for his first career touchdown catch.

''I knew he was one of the better guys on their defense, but I also knew he was a defensive end,'' Wilson said. ''I knew his hips weren't that good. He can't move side to side, especially when his whole body is turned. It's just a simple one step, cut across his face and get the ball. Whatever happens after happens.''

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.

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 winning drive.

''Jimmy's confidence never wavers,'' fullback Kyle Juszczyk said. ''It's been like that all year. Any time he's made a mistake there's no letup on him. Everybody has all the confidence in the world in him and he always just does a good job of showing that confidence when he's in the huddle.''

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.

''Honestly, everything we had was there,'' Murray said. ''We shot ourselves in the foot a couple of times. At the end of the day, we had our chance to win the game. We just did not put them away. They're a good team. When you play good teams, you cannot do that.''

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.

INJURIES

49ers DE Dee Ford left in the first half with a hamstring injury.

FLAG DAY

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 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.

UNDRAFTED GEMS

All four 49ers touchdown catches came from undrafted players. Backup tight end Ross Dwelley had two playing for the injured George Kittle, Kendrick Bourne added one in the fourth quarter and Wilson had the game-winner. It was just the 10th time since the merger that a team got four TD catches from undrafted players in a single game.

UP NEXT

Cardinals: Week off before hosting the Los Angeles Rams on Dec. 1.

49ers: Host Green Bay on Sunday.

---

More AP NFL: https://apnews.com/NFL and https://twitter.com/AP-NFL

Copyright 2019 by STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.