LAS VEGAS (AP) — San Francisco coach Kyle Shanahan said his team has been in playoff mode for several weeks as it fights for a top seed in the NFC, and Sunday had a postseason atmosphere.

Playing in front of a raucous pro-49ers crowd as visitors in Las Vegas, San Francisco was pushed like it seldom has been during what’s now a nine-game winning streak.

Tashaun Gipson intercepted Jarrett Stidham in overtime and returned it 56 yards, setting up Robbie Gould’s 23-yard field goal that gave the Niners a 37-34 win over the Las Vegas Raiders.

“It’s tough to win nine in a row,” Shanahan said. “We pulled it out. We got some guys who stuck with it. No one got frustrated and they just kept battling regardless, and the Raiders answered so many times.”

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 bye if Philadelphia loses to the Giants in Week 18.

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

Christian McCaffrey rushed for 121 yards and caught six passes for 72 yards. San Francisco’s midseason trade acquisition surpassed 1,000 yards rushing for the third time and has scored touchdowns in five consecutive games.

“That’s the kind of the game you dream about as a kid,” McCaffrey said. “It’s so back and forth, and you have to fight and claw your way back. It was good for us to have that game.”

Davante Adams had seven receptions for 153 yards and two touchdowns for the Raiders (6-10), who were eliminated from playoff contention. They have lost three of their past four games, and this was their NFL-record fifth defeat this season after holding a double-digit lead in the second half.

Stidham, who replaced Derek Carr 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. Gipson’s decisive pick in OT was set up when defensive end Nick Bosa bull-rushed Raiders left tackle Kolton Miller into Stidham as he was releasing the ball.

“I didn’t feel like I had really any nerves at all this week,” Stidham said. “Perspective has changed a lot over the years. It’s not worth stressing over and getting all uptight, so I wanted to go out there and play free today and tried to facilitate the offense in a way to win. We fell short a little bit.”

The teams traded touchdowns in the final two-plus minutes of regulation. Jordan Mason’s 14-yard run with 2:17 left put San Francisco ahead 34-27, but Stidham quickly moved the Raiders down the field, aided by a pass-interference penalty, and Josh Jacobs scored from 1 yard out to tie it.

Brock Purdy then led the Niners to the Las Vegas 23, but Gould missed a 41-yard field goal on the final play of regulation.

Stidham led the Raiders to 10 points on their first two drives, the first time San Francisco has allowed an opponent to score on its first two series this season.

But Purdy was even better, throwing 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. He is the fifth rookie to win his first four starts.

“He handled (the pressure to come back) great,” said 49ers receiver Brandon Aiyuk, had nine catches for 101 yards and a TD. “Super calm dude, super calm dude. The moment was never too big for him.”

The Raiders took a 17-14 lead at halftime when Stidham threw a 4-yard fade to the left side of the end zone to Adams, who leaped 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.

Las Vegas took a 24-14 lead early in the third quarter when Stidham found a wide-open Adams for a 60-yard touchdown.

INJURIES

49ers: G Aaron Banks (knee, ankle) and LB Dre Greenlaw (back) were injured. Shanahan said Banks will have an MRI for what he believes is a sprained MCL.

Raiders: Jacobs (hip) went into the locker room in the first quarter but returned in the second quarter. … LB Darien Butler (concussion) departed in the second quarter.

UP NEXT

49ers: Try to improve their playoff positioning when they host Arizona next weekend.

Raiders: Host Kansas City to close the season.

___

AP NFL: https://apnews.com/hub/nfl and https://twitter.com/AP_NFL