For most of the night, the Battle of the Bay looked like the Rout of the Drought.

No. 4 Stanford had a 30-point lead on No. 21 Cal early in the second half. Then the Bears came to life and made a spectacular comeback to cut the lead to five in the final minute.

Stanford had to hang on for dear life for a 70-64 victory Thursday night as Cal was unable to reprise last season’s win over Stanford at Maples Pavilion.

A three-point basket by Cal’s Afure Jemerigbe with 17 seconds left cut the lead to 69-64.

Mikaela Ruef hit a foul shot with 14 seconds left for the final score.

The Cardinal used a 12-point flurry at the end of the first half to take command of the game. But Gennifer Brandon, rounding into form after a 10-game layoff, keyed a 12-0 run for the Bears that cut the lead to 59-43 with 9:10 left.

The Bears were far from done. Brittany Boyd, who scored 25 points, and Jemerigbe (18) keyed a rally that had the Cardinal reeling.

Cal didn’t shoot its first foul shot until Gennifer Brandon went to the line with 5:45 left and made one of two. Cal wound up 6-for-12 from the line, Stanford 11 for 16.

Stanford (20-1 overall) completed the first half of the Pac-12 schedule with a 9-0 mark. It plays Cal (14-6, 6-3) again Sunday at 1 p.m. at Haas Pavilion.

It was Stanford’s sixth straight win over a ranked team after losing to No. 1 UConn in November.

Chiney Ogwumike had 23 points and 12 rebounds, while Karlie Samuelson added 14 points and Taylor Greenfield 10. Ruef had eight points and 12 boards

A 12-0 run put Stanford up 59-29 before a Boyd floater ended Cal’s skid.

Samuelson came off the bench to score 12 points in the first half – one more than Ogwumike. Stanford closed the half with a 12-0 run to take a 43-25 lead.

The Bears shot just 31 percent in the first half, missing one makeable shot after another. Stanford meanwhile hit 50 percent from the field, although a subpar 27 percent from 3-point land.

Ogwumike, guarded closely for most of the first half by Justin Hartman, connected on just 4 of 9 shots, well below her usual accuracy.

Stanford was not called for a foul until almost the 10-minute mark. The Bears didn’t attempt a free throw in the first half.

Cal is easily the worst three-point shooting team in the Pac-12, making just 24 percent of its tries, while Stanford entered the game as the best at 41 percent. Cal, however, made as many treys at Stanford – three – in the first half.