C.J. Beathard threw two touchdown passes to Kyle Juszczyk, Jeff Wilson Jr. rushed for a career-best 183 yards and Ahkello Witherspoon thwarted a late Arizona Cardinals threat with an end-zone interception Saturday afternoon, lifting the visiting San Francisco 49ers to a 20-12 victory in Glendale, Ariz.

The loss was a costly one for the Cardinals (8-7), who with a third consecutive victory could have earned a wild-card playoff berth by winning their last two games. Instead, now the Chicago Bears (7-7) can eliminate Arizona by winning their last two, including Sunday at Jacksonville.

Juszczyk’s touchdown catches covered 9 yards in the third quarter and 1 yard in the fourth, allowing the 49ers (6-9), who snapped a three-game losing streak, to extend a 7-6 halftime edge.

When Robbie Gould missed right on his point-after attempt following Juszczyk’s second score with 8:36 remaining, the Cardinals needed a touchdown and two-point conversion to tie.

Murray drove Arizona to the San Francisco 14, but his floater intended for Christian Kirk was picked off by Witherspoon.

Arizona got the ball back one more time after Gould missed his second field goal attempt of the day, a 37-yarder with 1:09 remaining. But the Cardinals couldn’t get out of their own territory as Murray finished a 31-for-50, 247-yard, touchdown-less game.

Starting in place of injured Raheem Mostert, Wilson rushed 22 times and hauled in Beathard’s first of three touchdown passes, a 21-yarder in the first quarter.

Beathard, San Francisco’s third-stringer getting an opportunity with both Jimmy Garoppolo and Nick Mullens out, went 13-for-22 passing for 182 yards and the three scores.

DeAndre Hopkins was the game’s top pass-catcher with eight for 48 yards, while teammate Kirk went for a team-high 76 yards on seven catches.

Kenyan Drake scored Arizona’s only touchdown on a 1-yard plunge with 12:08 left in the game, but a two-point conversion pass from Murray to Hopkins went incomplete, leaving the Cardinals two points behind at 14-12.

George Kittle, returning to the San Francisco lineup after suffering a broken foot in Week 8, had a game-high 92 receiving yards on four receptions.

Arizona’s Mike Nugent sandwiched Wilson’s touchdown with a pair of field goals — from 27 and 43 yards — to keep the Cardinals with 7-6 at halftime.