The seventh-seeded Bruins (17-15) built a 26-point lead before Stanford started hitting shots in the closing minutes to pull within 69-62.
UCLA hit 10 of 12 free throws in the final 1:05 to earn a spot in Thursday’s quarterfinals against No. 2 seed Arizona State.
Jalen Hill had 12 points and 10 rebounds, and Chris Smith added 14 points for the Bruins.
The 10th-seeded Cardinal (15-16) struggled against UCLA’s defensive pressure early, finishing at 35 percent from the floor and 7 of 25 from the 3-point arc.
UCLA’s regular season included some ugly early losses, the firing of coach Steve Alford and ended with losses to Colorado and Utah.
Stanford stumbled to the finish, losing four of its final seven games, including rival Cal in the finale.
The Bruins and Cardinal split the season series, each winning at home.
Neither team could get shots to fall early in the rematch, opening a combined 4 for 24. The Bruins started to find the range and hit eight of nine shots to build a 31-18 lead.
Hands had 13 points and UCLA led 36-22 at halftime.
Stanford had a scoreless drought of more than four minutes, shot 8 of 35 and went 1 for 11 from the 3-point line in the first half.
The trend continued early in the second half and UCLA went on a 12-2 run to build its lead to 57-31 midway through.
Stanford finally started hitting shots midway through the second half, but ran out of time.
Stanford was unable to find the range until late, digging a big hole it couldn’t shoot out of to get knocked out of the Pac-12 tournament by UCLA for the second straight season.
The Bruins were superb defensively until the midpoint of the second half, then had a hard time stopping the Cardinal. They’ll need to finish better to have a chance at beating Arizona State.
Stanford awaits word if it gets an invite to a postseason tournament.
UCLA faces Arizona State in the quarterfinals.