Updated

Stanford stayed right with the nation's No. 1 team despite going cold and failing to convert down the stretch.

Even with a nearly 9-minute scoring drought in the second half, coach Johnny Dawkins' Cardinal had a chance to tie the game on the final shot. Another disheartening close call for this bunch.

Nick Johnson hit a go-ahead 3-pointer with 51 seconds remaining and made two free throws with 5.8 seconds left as Arizona survived for a 60-57 victory over Stanford on Wednesday night for its school-record 21st straight win.

"It's disappointing, especially the way we played," Dawkins said. "Falling short means there are no moral victories. For us, we have to look at how can we get better? There's still a big upside for our team and we have time to still continue to improve. I think we showed that tonight."

After Johnson hit a jumper in the middle of the key with 2:36 remaining to make it 55-53, Dwight Powell answered on a baseline drive with 1:21 to go before Johnson delivered once more.

Johnson finished with 16 points, five rebounds and four assists and T.J. McConnell added 11 points, eight rebounds and four assists for Arizona (21-0, 8-0 Pac-12), off to the program's best start in conference play in more than a decade.

Arizona is one of three unbeaten teams left in Division I, joining No. 2 Syracuse, which also won Wednesday night. Fourth-ranked Wichita State hasn't lost either.

Powell and Josh Huestis each scored 13 points for Stanford (13-7, 4-4), which outshot Arizona 38 percent to 36 percent.

"Coming off any loss, it's tough to sleep at night," Huestis said. "But of course this is going to weigh heavily on guys' minds. You can go one of two ways. You can either pick you head up, learn a lesson from it and get ready for the next one. Or you can allow it to mess you up for the next game. I am sure our guys are going to ready to go the next game."

Johnson missed a free throw with 28 seconds left and Stanford called time out. Huestis missed a 3 from the left wing and Aaron Gordon secured the rebound, but he also missed a free throw giving the Cardinal one final shot.

Chasson Randle missed a long 3 just before the final buzzer for Stanford.

"I thought I got a good look at it," Randle said. "It was just one of those nights."

After a 3-pointer by Huestis with 10:03 remaining, Stanford didn't score again until Powell's layin at 1:21 — and Powell missed two free throws at 4:36 that would have put his team ahead.

"For 38 minutes, I thought we were right there," Dawkins said. "Credit Arizona for making the plays they had to make at the end. Nick Johnson stepping up, whether at the foul line or whether it was a 3-point bucket late. I've watched a lot of tape of them, he's done it all year."

The Cardinal beat two Top 25 teams already with victories at then-No. 10 Connecticut and at then-No. 17 Oregon earlier this month.

But not this time given their struggles in the waning moments at Maples Pavilion, which hosted a No. 1 men's team for the first time since losing 72-69 to Arizona on March 1, 2003.

The Wildcats had a large contingent of fans in the crowd cheering "U of A! U of A!"

McConnell's jumper at 10:58 gave Arizona its first lead of the opening half. Gordon, from nearby San Jose, scored his first points midway through the half and Arizona missed four of its initial five 3-point attempts.

Anthony Brown beat the halftime buzzer with a basket to put Stanford ahead 31-30 at the break. Arizona had trailed at halftime several times already this season only to produce a big second half.

"We're an outstanding defensive team. It isn't as if we changed any scheme, we just buckled down and had a lot of players playing very hard, and our ability to hold them to what we did is a big reason we won," Arizona coach Sean Miller said. "Our defense won the game tonight."

Stanford's last home win against a No. 1 team came against Arizona, 82-74, on Feb. 4, 1988.