PHOENIX — Even on a night when Arizona coach Sean Miller shattered his clipboard out of frustration, he found it a great time to be an instructor.

The Wildcats not only learned several lessons in a 67-64 win over Texas A&M on Tuesday at Talking Stick Arena, but also collected a win over the seventh-ranked team that just might vault them back into the Top 25 polls if they can also beat Alabama on Saturday at McKale Center.

Still unbeaten in the United States, the once-second-ranked Wildcats are still trying to live down — and grow up from — an 0-3 performance in the Bahamas over Thanksgiving that dumped them from the polls.

In Miller’s mind, they’re also trying to power through the more difficult section of their nonconference schedule and turn the corner toward the Pac-12 season with some momentum.

“This is something you want to do to maybe prepare your team for bigger things down the road,” Miller said. “But in the meantime I think we continue to progress from maybe the team we were in the Bahamas. As you can see by watching us, we still have some things we have to do better.”

They do. Things like not fouling a 3-point shooter when you’re up three with two seconds left and not allowing easy jumpers, as the Wildcats did during a second-half possession when Miller threw his clipboard down as his team entered a huddle, and shattering it.

Arizona survived the 3-point foul gaffe because Texas A&M’s Duane Wilson missed the first of three ensuing free throws — and then, when he tried to miss the third one intentionally in order to give his team a crack at a rebound basket, made it.

That problem forced the Aggies to immediately foul UA’s Dylan Smith, who then hit two final free throws to seal the win for Arizona, which moved to 6-3 while Texas A&M dropped to 7-1.

“It’s always great to go through these situations at the end of the game,” Miller said. “We were going to foul obviously on purpose but when you do that you have to do it right at the half court line and we had younger group. We didn’t communicate. Parker (Jackson-Cartwright) got backscreened and we ended up fouling a 3-point shooter, which you never want to do.

“So that’s a lesson learned and I’m glad we can learn it with a win.”

Deandre Ayton actually was called for the foul on Wilson, but it’s been hard to blame him for just about anything the Wildcats have done this season.

He finished with his seventh double-double in nine college games, with 13 points and 10 rebounds, while Miller cited the swarming defensive attention he commanded for opening up shots for everyone else.

As a result, three other UA players also scored 13 points to lead the Wildcats, including Smith, Brandon Randolph and Dusan Ristic, who was a machine-like 5-of-7 after also leading UA to a 67-63 win against the Aggies a year ago in Texas with 18 points.

“Statistically, (Ayton) might have had better games this year but you gotta realize they’re double-teaming and triple-teaming and crowding, and that opens things up for his teammates,” Miller said.

Ayton also played a big role at the end, defending Texas A&M center Tyler Davis as he drove the baseline for a potential game-tying basket with UA leading 64-62.

Davis pushed and leaned and kept control of the ball … but never did move his feet much and was called for traveling. That allowed UA to take possession, eventually getting 1 of 2 free throws from Randolph with five seconds left that led to the three-point advantage before Ayton fouled Wilson at the 3-point line.

“I don’t think I traveled,” Davis said about his move on Ayton. “But it was called, so we had to execute after that.

They didn’t. Texas A&M wound up scoring only one field goal over the final 3:24, a layup from Davis with 17 seconds left.

It also hurt the Aggies that the Wildcats took 14 more free throws, with Arizona making 20 of 24 and Texas A&M going 7 for 10. That’s a 13-point difference that easily cost the Aggies the game, as Texas A&M coach Billy Kennedy noted.

What’s worse for the Aggies is that when Wilson was given those precious three free throws with two seconds left, he whiffed.

It was a mild shock considering that Wilson had made 18 of 19 free throws he had taken so far this season, though he was only a 68.6-percent free throw shooter in three previous seasons at Marquette before transferring last spring.

Kennedy suggested Wilson was thrown off by the officials’ review of the foul and where Wilson stood when Ayton contacted him

“He’s really a great free throw shooter,” Kennedy said. “I don’t know why the referees took so long so he had a long time to think about it. It was a tough situation.”

Trailing by two points at halftime, Arizona took leads of no more than four points in the second half and hung on, taking the lead for good when Parker Jackson-Cartwright hit his 3-pointer from the right corner as he fell to give UA a 61-58 lead with 1:55 left.

After the teams each failed to score on their next possessions, Texas A&M’s D.J. Hogg was fouled by Allonzo Trier with 29 seconds left.

Hogg hit both free throws to pull the Aggies within 61-60 and, after Brandon Randolph hit two free throws for Arizona, Tyler Davis hit an eight-foot hook shot to pull Texas A&M back within one with 17 seconds left.

But the Wildcats had two free throws from Randolph with 17 seconds left and Texas A&M missed a chance to tie it up with seven seconds left when center Davis backed into Ayton along the baseline but took too many steps without a dribble and was called for traveling.

Texas A&M took a 55-54 lead into the final four minutes of the game, having received two tough field goals in a row from Davis, who lofted one of them from the side of the backboard as he jumped up from the baseline.

Trailing 41-39 at halftime, the Wildcats stayed within or ahead of the Aggies by a basket through the first 10 minutes of the second half and had a potential momentum-changer at the midway point of the half, when Randolph drove for a layup and appeared to be grabbed around the head by Texas A&M’s J.J. Caldwell as he neared the basket.

Officials ruled it a flagrant foul on Caldwell, and Randolph hit both ensuing free throws to give UA a 47-45 lead, but Caldwell stole the ball when UA took possession after the free throws. Caldwell went on to turn it over himself, but Texas A&M eventually took a 49-47 lead when Hogg hit a 17-footer from the right wing.

Appearing to be displeased with Smith’s defense on that play, Miller had a few words with him entering a timeout and then Miller threw his clipboard on the floor and broke it.

But by the end of the game, Miller appeared to feel pretty good. The Wildcats have now won three straight, including respectable wins at UNLV and over Texas A&M.

“These last two games,” Miller said, “these guys have a much better understanding of what it takes.”

Outbrain