LAS VEGAS — Robbie Gould’s 23-yard field goal with 6:53 left in overtime lifted the San Francisco 49ers to a 37-34 triumph Sunday — their ninth straight victory — and knocked the Raiders from playoff contention.

The victory was especially important for the 49ers (12-4), who can clinch the No. 2 seed in the NFC with a win against Arizona next week or a loss by Minnesota. San Francisco also has a shot at the No. 1 seed and a first-round bye if Philadelphia loses to the Giants in Week 18.

San Francisco overcame a rare off day from what was the league’s top-rated defense entering the game. The 34 points were the most the 49ers have allowed since a 44-23 loss to the Kansas City Chiefs on Oct. 23, which also was San Francisco’s most recent loss.

Christian McCaffrey helped keep the Niners’ winning streak going, rushing for 121 yards and catching six passes for 72 yards. He surpassed 1,000 yards rushing for the third season and has scored touchdowns in five consecutive games.

San Francisco’s Robbie Gould follows through on a 23-yard field goal for a 37-34 overtime victory Sunday over the Raiders at Allegiant Stadium. (AP Photo/John Locher)

The Raiders (6-10) have lost three of their past four.

Jarrett Stidham, who replaced Derek Carr as the Raiders’ starting quarterback after the nine-year starter was benched earlier in the week, completed 23 of 34 passes for 365 yards. He joined Kansas City’s Patrick Mahomes as the only QBs this season to throw three touchdown passes against the 49ers.

Stidham also threw two interceptions. Tashaun Gipson intercepted Stidham in overtime and returned it 56 yards to set up Gould’s game-winning field goal.

Stidham came out firing from the beginning, leading the Raiders to 10 points on their first two drives, the first time this season San Francisco has allowed an opponent to score on its first two series.

Niners quarterback Brock Purdy, however, matched Stidham’s play with two touchdown passes to put San Francisco ahead 14-10 early in the second quarter. It was the fifth game in a row Purdy has thrown multiple TD passes, the longest streak in 49ers history since Jeff Garcia put together an eight-game streak in 2001. Purdy finished 22 for 35 for 284 yards and two touchdowns and an interception.

But the Raiders took a 17-14 lead at halftime when Stidham threw a 4-yard fade pass to the left side of the end zone to Davante Adams, who made a leaping grab and somehow kept both feet inbounds. That play made Adams the eighth receiver in NFL history with at least three seasons catching 13-plus TD passes. Adams had seven catches for 153 yards and two touchdowns.

The Raiders led 24-14 early in the third quarter when Stidham found Adams for a 60-yard touchdown.

But then the Niners rallied.

The teams traded touchdowns before Gould had a chance to win the game in regulation. However, he missed a 41-yard field goal as time expired.

Brandon Aiyuk had nine catches for 101 yards and a touchdown for San Francisco.