It was going to be a terrible loss ... until it wasn't.

Jeff Wilson saved the 49ers' bacon Sunday against the visiting Arizona Cardinals when he caught a 25-yard touchdown pass from Jimmy Garoppolo with 31 seconds left in the fourth quarter to put San Francisco back in front 29-26. Kicker Chase McLaughlin then converted the resulting extra point to give the 49ers a four-point lead.

On the first play of Arizona's next possession, defensive lineman Damontre Moore -- who signed with the 49ers earlier in the week -- forced a fumble that safety Jaquiski Tartt recovered. 

The Cardinals had one last chance with six seconds remaining, but they fumbled following a hook-and-ladder play that D.J. Reed ultimately returned for a touchdown.

With the 36-26 win, the 49ers remain in first place in the NFC.