The 49ers saw the return of Christian McCaffrey, gaining 413 yards, but Jake Moody’s three missed field goals kept the game close.
In the end, Moody kicked a 44-yarder on the final play to deliver a 23-20 victory over the hard-luck Bucs. It is the second consecutive game Tampa Bay has lost on the final play.
San Francisco moved to 5-4 with a second win in a row, while Tampa Bay fell to 4-6 with a fourth consecutive loss.
Moody also made a 28-yard field goal, but he missed field goals of 49, 50 and 44 in his return from a high-ankle sprain. The final kick, which ended a six-play, 39-yard drive, likely was a make-or-break kick for Moody.
The 49ers should have ended the game well before the last play, but the gutsy Bucs kept hope alive until the end.
Quarterback Baker Mayfield drove the Bucs 58 yards in 11 plays, eating up 2:28 of the final 3:09. Mayfield got away from Nick Bosa just enough to throw a pass up for grabs on fourth-and-7 and Rachaad White caught it for an 8-yard gain. The 49ers then had four defensive penalties for 39 yards.
Three came back-to-back-to-back with Fred Warner called for facemask on White, Maliek Callins for roughing the passer and Evan Anderson an illegal use of hands.
The Bucs stalled at the 8, and Chase McLaughlin kicked a 26-yarder to tie it with 41 seconds left. It was too much time for the 49ers.
McCaffrey rushed for 39 yards on 13 carries and caught six passes for 68 yards, and Brock Purdy completed 25 of 36 passes for 353 yards and two touchdowns. Jauan Jennings caught seven passes for 93 yards.
Mayfield was 18-of-29 for 116 yards and a touchdown, with White catching six passes for 39 yards and a touchdown and Bucky Irving rushing for 73 yards and a touchdown on 13 carries.