Purdue led 60-55 with 1:43 remaining before Darryl Morsell drilled a 3-pointer and Ayala finished up with three free throws. Ayala made 1 of 2 at the line with 48 seconds to go and hit the final two after missing a layup, collecting his own rebound and getting fouled by Jaden Ivey.
Purdue then committed a turnover before attempting a final shot.
Aaron Wiggins had 18 points and 11 rebounds for Maryland (10-8, 4-7) and Ayala scored 16. The Terps went 8 for 13 from beyond the arc in the second half after going 1 for 12 from long range over the first 20 minutes.
Trevion Williams had 23 points and 11 rebounds for the Boilermakers, whose three-game road winning streak ended.
The Boilermakers built a 36-30 lead before successive 3-pointers by Ayala and Wiggins tied the game for the ninth time. After Williams popped a jumper, Wiggins drilled a lengthy 3 to give Maryland its first lead since 9-8.
NO SASHA
The Boilermakers were without guard Sasha Stefanovic, who missed a second straight game following a positive test for COVID-19. Stefanovic is Purdue's second-leading scorer and the Big Ten's leading three-point shooter by percentage (45.6).