STANFORD — One amazing comeback deserves another.

In its first game since blowing a 17-point lead in the final 7 ½ minutes against rival Cal, the Stanford men’s basketball team fought back from a 12-point deficit in the final 5:48 of regulation and beat UCLA 107-99 in double-overtime Thursday night at a frenzied Maples Pavilion.

Freshman guard Daejon Davis made a crucial runner with 34.2 seconds left to effectively seal it, and punctuate a thrilling game that was won largely on the strength of the Cardinal’s heralded freshman class.

“We couldn’t guard Davis,” UCLA coach Steve Alford said.

Senior Dorian Pickens led the Cardinal with 26 points and 10 rebounds — including a dramatic three-pointer with 5 seconds left in regulation to send the game into overtime. Just two games into a comeback from a foot injury that kept him out seven weeks, Pickens played much of the late stages alongside four freshmen, after junior Reid Travis and senior Michael Humphrey fouled out.

“It was me and the young guys,” Pickens said. “And they played phenomenal today. They stepped up in a great way.”

The victory delivered the Cardinal (7-8) its first win in Pac-12 Conference play, and sends it into a home game against USC on Sunday on a high, one that coach Jerod Haase hopes will serve as a stepping stone to even bigger things.

“I’m going to do everything I can to make sure that this isn’t a flash in the pan,” he said. “This needs to be a building block moving forward.”

The Cardinal seemed to have it won, in the first overtime.

Freshman Kezie Okpala threw down a dunk with 32 seconds left in that first overtime, and fellow freshman Oscar Da Silva swatted away a potential game-tying shot by UCLA’s Aaron Holiday with 5 seconds left.

Okpala’s free throw made it 94-91, but Holliday drilled a shock three-pointer at the horn to force the second overtime.

Finally, though, the Cardinal pulled it out.

It held the Bruins (11-4, 2-1 Pac-12) scoreless over the final 2:45 of the second overtime, and celebrated a much-needed victory over a strong team after such a dispiriting loss. They did it in part by finally controlling Holiday, who’d been almost the entire UCLA offense late in the game.

Holiday finished with 31 points — his two free throws were the last points the Bruins scored — but missed two shots in the final minute that could have changed the outcome.

Either team could have won at the free-throw line, combining to shoot just 61 percent from the line and miss seven of eight fouls shots in the final 1:26 of regulation. The Bruins were 19 of 35 from the line.

“It was just atrocious foul shooting,” Alford said.

The Cardinal made the most of its misses, though, at least at the right time.

Trailing by one with barely two minutes left in the second overtime, freshman Isaac White missed two foul shots. But he rebounded his second miss, allowing Pickens to bury a three-pointer that gave Stanford a 101-99 lead that they never relinquished.

“Over and over and over again, we had adversity,” Haase said. “And we responded.”

Travis had 18 points and 11 rebounds for the Cardinal, and Humphrey had 14 points and seven boards, as well as a crucial blocked shot near the end of regulation. Okpala finished with 13 points after a miserable start.

The Bruins came in riding a four-game winning streak, a month after their high-profile split with freshman LiAngelo Ball, with one of the wins coming against then No. 7 Kentucky.

Yet the Cardinal cut their lead from 12 down to one in the space of five minutes late in regulation, and trailed just 83-82 once Da Silva scored a layup with 46 seconds left.

But Holiday drove for a layup with 24.5 seconds left to restore a three-point UCLA lead, and Davis missed two free throws, giving the Bruins the chance to escape. But UCLA’s Price Ali missed two free throws of his own, allowing Pickens to bury his three-pointer and send the game into overtime.

“I just threw a pump-fake, and he jumped,” Pickens said of his defender. “I had an opening to shoot, so I wanted to get it up. … Yeah, it felt good.”

Holiday and Kris Wilkes combined for 49 points for the Bruins, and forward Gyorgy Goloman added 14 points, though 7-foot center Tom Welsh was limited by a nose injury. The Cardinal trailed by just one point early in the second half, before Travis sat down in foul trouble and Holiday and Wilkes erupted, largely with lethal moves to the hoop.

Related Articles Pac-12 football: Cal, Stanford working to return but local health officials must sign off

Pac-12 football: Presidents may target Halloween for restart

Explaining the California restrictions governing practice for the Pac-12 teams: From a practical standpoint, it’s impractical

Coronavirus: Gavin Newsom says California has no restrictions preventing Pac-12 football’s restart

Hotline: With the Big Ten restarting, the Pac-12 stands alone. Whatever it takes, the conference must play this fall The duo scored 18 of the next 21 points for UCLA.

By the time Travis returned, the Cardinal were down 10 and appeared doomed.

Nevertheless, the Cardinal used a 9-0 run to cut the lead to 80-77 with 3:34 left, when Humphrey swatted a shot against the backboard and ignited a fast break that ended with Davis’ lay-up that ignited the crowd, and set the stage for the exhilarating finish.

“The guys had a belief in something bigger than themselves, greater than themselves, when there wasn’t a whole lot to hold on to,” Haase said. “There was a belief, for the first time since I’ve been at Stanford, that we can get this done.”