Bryce Alford added 18 points to help the Bruins build a 22-point lead early in the second half before holding off a furious Cardinal comeback. Chasson Randle's running 3-pointer missed as time expired.
UCLA (14-9, 6-4 Pac-12) has won six of eight following a five-game losing streak. The Bruins improved to 2-6 on the road and won their first non-neutral site game outside of Los Angeles all season.
Anthony Brown had 19 points and nine rebounds, and Randle scored 13 for Stanford (15-7, 6-4), which dropped consecutive games for the first time since last March. Stanford had won its previous eight games following a loss.
About the only thing UCLA didn't do well was close each half.
The Bruins led 31-15 with 3:29 left in the first half, seemingly ready to rout the home team. Instead, the Cardinal closed the period with 10 straight points, trimming UCLA's advantage to 31-25 at intermission.
The Bruins burst out of the locker room again with a 19-5 spurt, pouncing on the Cardinal's costly errors. They led by 22 with less than 11 minutes to play when Stanford slowly started to cut the deficit behind a series of long-range shots.
Brown's 3-pointer sliced UCLA's lead to 67-61 with 3:49 remaining. The Bruins grabbed three consecutive offensive rebounds to drain the clock, then watched Stanford missed twice on the other end.
After another botched Bruins possession, Rosco Allen split a pair of free throws. Stanford stopped UCLA again, then Brown put back a rebound to bring Stanford within three with 21.5 seconds to play.
The Cardinal got another chance when Powell missed the front end of a one-and-one, but Randall raced down out of control and lost the ball. Powell made 1 of 2 free throws, then Allen connected on a 3-pointer to cut UCLA's lead to 68-67 with 4.8 seconds left.
Alford was fouled with 3.3 seconds, but only made the second free throw.
Following a timeout, Randle hauled in a pass near half court. He took a couple of dribbles and attempted a running jumper a few feet beyond the arc that banked off the backboard, hit the front of the rim and bounced out.
Even with all the late drama, it was still an easier affair for UCLA than the last time they played Stanford. The Bruins outlasted the Cardinal 86-81 in double-overtime on Jan. 8 at Pauley Pavilion, which had been their only win over a team in the RPI top 50.
Now they have two.
UCLA: The Bruins have won nine of their last 11 games against Stanford, including six of nine at Maples Pavilion. ... UCLA's longest winning streak is four games this season.
Stanford: The Cardinal had won their last eight games after a loss. They hadn't dropped two in a row since losing to Arizona and Colorado last March.
UCLA: At California on Saturday.
Stanford: Host Southern California on Sunday.