Melo Trimble scored 22 points for Maryland. (Jonathan Newton/The Washington Post)

Maryland freshman Kevin Huerter remembered how cruel college basketball could be in a 73-72 loss to Purdue on Saturday. After watching his potential game-winning three-pointer graze off the front of the rim, he turned around and slammed his fist into one of the chairs on the team’s bench. It was the lasting image of a day that began with such promise, with the Terrapins riding their best start in school history and eager to play a ranked opponent for the first time all season.

It had been 34 days since the 17th-ranked Terrapins last lost, in a late-game meltdown on its own floor against Nebraska. What happened Saturday against the 23rd-ranked Boilermakers was eerily similar. Maryland blew a 12-point lead in the second half and went the final 7:37 without a field goal, instead subsisting on 14 points off free throws, 11 of them by Melo Trimble.

It was Trimble who had a chance to break the drought and give his team a three-point lead with 16 seconds left, but his pull-up six-foot jumper fell short. That was off a play that Maryland had rarely used this season, and even after it didn’t work, Terrapins Coach Mark Turgeon was confident his team would pull out its eighth straight win.

“I wanted to win it with defense,” he admitted later, shaking his head as he recalled what happened next: Purdue guard Carsen Edwards drew a foul on a driving shot with 2.1 seconds left, then hit two free throws to give his team a one-point lead.

Maryland (20-3, 8-2 Big Ten) still had two chances to win. The Terrapins attempted a long inbounds pass that was intercepted by Purdue center Isaac Haas. But Haas celebrated too early, walking toward center court with the ball still in his raised hand. He was called for traveling with a half-second left, giving the Terrapins another inbounds play, this time from under the basket. With the Boilermakers (19-5, 8-3) packing the paint, as they had done all day, Huerter was left open for a corner three-pointer that went begging.

“It definitely was an opportunity, but I think there’s going to be a lot more opportunities coming up,” said Huerter, who finished with 11 points. “It would’ve been a good win, to get the win, obviously, in front of our home crowd and kind of get some respect behind our name.”

A sellout crowd, including a student section that had stood in line a few hours before tip-off to get in, quietly filed out of Xfinity Center after the most anticipated game of the season. It marked just the third time that Maryland has lost to a Big Ten opponent on its home floor since it joined the league for the 2014-15 season.

“This one hurts because we played well enough to win,” said Turgeon, who still seemed bewildered by his team’s offensive struggles down the stretch.

Trimble finished with 22 points on 4-for-15 shooting, unable to outduel star sophomore forward Caleb Swanigan, who spearheaded Purdue with 26 points and 10 rebounds before fouling out with 56 seconds remaining. Swanigan and Haas — the ­7-foot-2, 290-pound mammoth who was jeered at every turn — overcame Maryland’s frontcourt, which received a career-high six blocks from junior center Michal Cekovsky and another four from senior center Damonte Dodd.

“Our post guys were great in post defense,” Turgeon said. “They outrebounded us by three [40-37] . . . and that’s pretty good for us. We battled.”

But that couldn’t mask Maryland’s inability to make a shot after it took a 52-40 lead on a vicious one-handed dunk by Huerter, set up by an assist from Cekovsky, with just less than 14 minutes to play. Cekovsky played just 13 minutes yet finished with 10 points, including an alley-oop dunk that gave his team a 58-55 lead. Swanigan responded by tying the game with a three-pointer with 7:20 remaining.

Trimble found another gear shortly after, calling for the ball and doing everything he could to get to the rim on several possessions. After hitting a pair of free throws to give his team a 62-60 lead, Trimble received the ball on the ensuing possession, running right into Haas on the left perimeter with 5:36 left. After being called for the foul, Haas was visibly frustrated and received a technical foul, sending Trimble back to the line to help give Maryland a 65-60 lead.

But then came another inexplicable scoring drought, accentuated by ill-advised deep three-point attempts by Huerter and freshman Anthony Cowan while the Boilermakers made a 6-0 run to retake the lead. Even after Maryland had regained a three-point lead on a pair of free throws after Trimble drew the fifth and final foul on Swanigan, Maryland’s usual late-game moxie — the formula that has helped produced nine wins by six points or fewer this season — didn’t seem the same.

“We’re used to winning close games, not used to losing,” Turgeon said. “Today we just couldn’t get that last stop.”