The 49ers were expected to brush aside the Raiders, for whom Jarrett Stidham was making his first NFL start at quarterback after they benched Derek Carr, but the anticipated blowout did not materialise.
Instead, the Niners were drawn into a compelling shootout, their league-best defense surrendering 500 yards to the Raider offense as Stidham delivering a stunning debut.
The 49ers trailed 24-14 in the third quarter but, even after overturning that deficit, were still forced into overtime despite Purdy delivering with the game on the line.
Having seen the defense quickly surrender a 34-27 advantage as the Raiders tied the game with 71 seconds remaining in regulation, Purdy gained 52 yards on four completions to wide receiver Brandon Aiyuk to put the Niners in range for a game-winning field goal, only for Robbie Gould to push his kick wide right.
A Tashaun Gipson interception in overtime gave Gould the chance for a reprieve, his 23-yard kick giving the 49ers a ninth straight win that saw them improve to 12-4 and move up to the second seed in the NFC playoffs.
It marked the first time Purdy, who became the fourth rookie quarterback to win his first four starts since 1950, had dealt with playing from behind.
And Shanahan was delighted to see him come through the experience.
"I think that was great for him," said Shanahan. "We had to come from behind, especially there at the end. Also, he made a ton of plays today, but there's a number that he missed too.
"And that's the coolest part. There were some he'd love to have back. It was never one way too much or the other where he was struggling or doing well, but there were some mixed plays.
"To keep coming back and keep attacking, he never got gun-shy, made some real good decisions too and fought it out throughout the whole game and found a way to win."