BROOKLYN, New York — With about 15 seconds left in Maryland men’s basketball’s battle with Kansas State for the Barclays Center Classic title Saturday night, Wildcats forward Wesley Iwundu stepped up to the foul line looking to extend his team’s lead to three.

Iwundu missed the front end of a one-and-one, and guard Melo Trimble got the rebound with the Terps trailing by one. As soon as Trimble came down with the rebound, Kansas State coach Bruce Weber knew what was coming next. He had even discussed it with his players during a team huddle moments earlier.

Still, the Wildcats failed to stop it.

With what Weber called “a head of steam,” Trimble drove down the lane, absorbed contact and finished with his left hand to put Maryland up one with 6.6 seconds remaining. He missed the free throw, but the Terps secured the 69-68 win after Kansas State’s last-second three-point attempt clanged off the front of the rim.

“I’ve been through that situation since I’ve been at Maryland,” Trimble said. “I just know the best decision, and that’s to kind of, when the game’s going like that, just go to the basket. Even though we weren’t getting calls, I needed to attack the basket, and I did that.”

The Terps (7-0) ran after the tournament’s Most Outstanding Player around the court to celebrate before posing for a team photo as the champions, marking the program’s fourth straight holiday tournament title. They’ve also won the Paradise Jam, the CBE Classic and the Cancun Challenge during that stretch.

“Melo just does what he does late in games,” Turgeon said.

Trimble, the team’s leading scorer (21.7 ppg) entering the contest, had 18 against Kansas State (5-2), while freshmen guards Kevin Huerter and Justin Jackson scored eight and 11 points, respectively. Maryland, which has lacked a go-to interior scoring presence to start the season, also received 16 points from forward Michal Cekovsky on 7-for-11 shooting.

Wildcats forward D.J. Johnson, meanwhile, led all scorers with 26 points.

Johnson scored 11 of those points in the first half on 5-for-11 shooting, but the Terps stayed with Kansas State throughout the opening 20 minutes thanks to a new sense of energy they lacked against Richmond the night before. The Terps beat the Spiders, 88-82, in overtime but had to overcome a 12-point halftime deficit. It marked the third game this season Turgeon’s team squeaked out a win against a mid-major foe.

“We have to change who we are, our approach to the game,” Turgeon said Friday night. “We’ve been lucky enough to squeak by American and Towson, and Stony Brook hung around with us, and we have to change.”

Behind 44.4 percent shooting and five turnovers, the Terps entered the break Saturday night with a six-point lead against perhaps the toughest opponent they played this season.

In a back-and-forth affair after intermission, Cekovsky had a series of dunks midway through the second half to help the Terps maintain their lead and ignite the crowd, which bellowed “Let’s go Ceko” chants throughout the arena. Down the stretch, Trimble got into the lane, either finishing layups or getting to the foul line.

But Kansas State matched their contributions. In fact, with Johnson scoring down low and guard Kamau Stokes doing damage on the perimeter — he scored all of his 11 points on jump shots in the final nine minutes — the Wildcats held a three-point lead with about 25 seconds to play.

At that moment, Trimble did what both Weber and Turgeon expected from the All-Big Ten performer. He started the sequence with a layup, cutting the Kansas State lead to 68-67.

“His one that cut it to one was an amazing play,” Turgeon said. “He put that one in, which was big time.”

Then, in the final seconds, Trimble channeled his closing ability to put Maryland ahead for good.

With his teammates chasing him after the final buzzer, Trimble saw fans clad in red in the first row. He assumed they were part of the Maryland faithful, so he sprinted toward midcourt, sharing embraces with those who have seen him star late in games so many times before.

“I was just happy we won,” Trimble said. “I didn’t know what to do.”