Brock Purdy threw for one touchdown and Christian McCaffrey ran for another to lift San Francisco over the Carolina Panthers 20-9 on Monday, boosting the 49ers' NFL playoff hopes.

The 49ers improved to 8-4, closing the gap on the NFC West division-leading Los Angeles Rams (9-2) and second-placed Seattle (8-3).

"It was a great win," McCaffrey said. "But I know we're hungry for more and I know we can be better."

Carolina fell two games adrift of the 49ers in the wildcard playoff hunt at 6-6 and dropped behind leader Tampa Bay (6-5) in the NFC South race.

Purdy, who won in his return last week after missing eight games with a toe injury, was intercepted three times but still able to throw for 193 yards and lead the 49ers to a vital victory.

McCaffrey ran 24 times for 89 yards and caught seven passes for 53 yards.

Jauan Jennings caught a 12-yard touchdown pass from Purdy, escaping two would-be tacklers to reach the end zone as the 49ers took a 7-0 lead after a game-opening 15-play, 75-yard drive.

Purdy interceptions killed the next three 49ers drives, two of them pickoffs by Carolina's Jaycee Horn, the last setting up Ryan Fitzgerald's 25-yard field goal for Carolina with 2:28 remaining in the second quarter.

San Francisco answered on a 47-yard Matt Gay field goal to lift the 49ers ahead 10-3 at half-time.

McCaffrey's 12-yard touchdown run against his former club late in the third quarter gave the 49ers a 17-3 edge.

Carolina responded with a 68-yard touchdown drive capped by Bryce Young's 29-yard touchdown pass to Tetairoa McMillan.

But a two-point conversion pass failed and the Panthers trailed 17-9 entering the fourth quarter.

Gay added a 29-yard field goal to put San Francisco ahead by the final margin.