Eric Ayala could not find space when he needed it. Losing by one to Purdue with time winding down, the Maryland men’s basketball guard was being hounded by Trevion Williams, the Boilermakers’ big man sealing off any lane to the basket.

As the clock hit seven, six, five, Ayala had to make a move. So he put his shoulder down, drove to the paint and spotted up for a two. It didn’t fall.

But Ayala kept going.

He crashed the net and secured the rebound. With Williams and his teammates over top of him, Ayala hoisted up a prayer. And then the whistle came. Jaden Ivey had fouled Ayala, giving the Terps a chance to win the game at the line.

And the junior delivered, calmly swishing both free throws to give his squad a one-point lead for good. Ayala teamed with Aaron Wiggins for an explosive second half, helping Maryland outlast No. 24 Purdue, 61-60, on Tuesday evening.

“I felt like I could get to the paint,” Ayala said. “I figured I was going to get a foul on the second one because I jumped up so fast that everyone was kinda still in the air coming down, and they got me.”

Much of the game was decided down low, dictated by Williams. He was relatively quiet back on Christmas Day, playing just 16 minutes due to foul trouble. But the 6-foot-10 forward was a force all night in College Park.

Primarily working on Galin Smith, Williams imposed his will on the Terps’ frontcourt. He scrapped down low for nine first-half points, cemented by a thunderous dunk to give the Boilermakers a two-point lead partway through the frame.

He was also a menace on the glass, outworking all willing Maryland challengers for four boards in the opening 20 minutes, including an offensive rebound. Purdue (12-7, 7-5 Big Ten) excelled on the glass all evening as the Terps’ small lineup could not contain the Boilermakers’ physicality and size. Purdue snagged 17 boards to Maryland’s nine in the first, including six on the offensive glass.

[With Waka Flocka Flame’s help, Maryland men’s basketball is keeping spirits high]

“Purdue’s a heck of a team, especially when [Williams] plays like that,” coach Mark Turgeon said. “Those big guys are loads, man.”

But despite those struggles, the Terps’ defense held serve, forcing 11 turnovers and keeping the Boilermakers to 41.7 percent shooting in the first. And on the rare occasions when Purdue dropped one through the twine, Maryland (10-8, 4-7) usually responded in kind.

A Williams jumper was followed by a Donta Scott layup, while Jairus Hamilton responded to Brandon Newman’s three with a deep shot of his own. Neither team led by more than five in the opening period, and the Boilermakers took a 27-24 lead into the break.

“Our defense was great tonight,” Wiggins said. “We guarded, and that’s what kept us in the game.”

But when the teams returned from the locker rooms, Williams went to work. He backed down Scott in the paint on three straight possessions, drawing a shooting foul and dropping two layups.

Just as it seemed the Terps had no answer for Williams, he gave them an opening. An errant pass ended up in the hands of Darryl Morsell, who pushed Maryland up the floor. He found Ayala, who faked a pass before calmly draining a three.

And then Williams missed a jumper. Wiggins marched down the court and drained from deep to tie the game at 36. Though Williams responded with a lay-in, Wiggins swished from long-range once again to give the Terps their first lead since the contest’s opening minutes.

“He’s definitely a microwave,” Morsell said. “Once he hits one, he’s bound to hit anything.”

The Terps had life. Just 1-of-12 from deep in the first half, Maryland — led by Wiggins and Ayala — seemingly could not miss. The juniors accounted for 25 of Maryland’s 37 second-half points, including a run where they combined to drill 17 in a row.

[Maryland men’s basketball couldn’t get out of its own way in Wisconsin loss]

But the surge wouldn’t last. And as he did all game, Williams responded.

The junior keyed an 11-4 Purdue run, scoring six points to stretch the Boilermakers’ lead to a game-high seven. Ivey got in on the act too, securing five points during the run to compliment Williams.

Yet, just as Purdue was ready to put the game out of reach, Maryland responded. Morsell scored six points in the final 2:48 for the Terps, hitting from beyond the arc, in the paint and at the line. However, missed free throws set the stage for a dramatic finish.

Ivey had the chance to bury Maryland with under a minute to go, but clanked a turnaround jumper, giving the Terps the ball with 16 seconds remaining. Ayala’s free throws put them ahead, and after the Boilermakers failed to execute a full-court inbounds play with three seconds on the clock, Maryland was celebrating its first home conference win of the season.

“It’s no fun losing,” Turgeon said. “To get a little enjoyment, and guys to be happy and hugging each other and all that after the game, it’s really good medicine, good therapy.”