Down by three points with time winding down, a broken play that found its way to Anthony Cowan offered Maryland men’s basketball a lifeline. The senior guard chucked up a 30-some foot 3-pointer from the “Gary Williams Court” script and sank it.

And on the following possession, Cowan dove for the loose ball, came up with it and got fouled, sending him to the free-throw line to win a game the Terps had once trailed by 15 points at the beginning of the second half.

“A miracle,” Illinois guard Ayo Dosunmu said. “A Christmas miracle, they got.”

There’s no rhyme or reason to the way Maryland won at Xfinity Center on Saturday night. For 38 minutes, the team had trailed. But it’s those final 19 seconds before the final buzzer that mattered, those 19 seconds that included the ball in Cowan’s hands.

And as the Terps mobbed Cowan, the Fighting Illini were left to wonder what could have been if their opponent hadn’t hit two unlikely threes — one from Jalen Smith with 2:36 remaining and the final dagger from Cowan.

“There was a lot of tears in there, there was a lot of hurt,” coach Brad Underwood said. “Maryland’s No. 3 in the country for a reason.”

[Read more: Anthony Cowan’s late heroics propel No. 3 Maryland basketball to 59-58 win over Illinois]

For the better part of the second half, both sets of offenses looked stagnant. Illinois went on a five-minute field goal drought to end the game, while Maryland finished on an 11-1 run, finally waking up despite still shooting 33 percent overall.

With under three minutes to play, the Fighting Illini focused on Cowan. When Smith set a screen at the top of the key, both defenders followed the senior guard. Cowan dished to Smith, and Dosunmu ran to meet him.

But the Illinois guard played averages — Smith entered the game shooting just 22 percent from beyond the arc — and retreated to leave Smith alone at the three-point line.

Smith pulled up and knocked it down, pulling the Terps within four points.

“Give him a lot of credit,” Underwood said. “He made four on the year [before Saturday] … He made a tough shot.”

[Read more: “It’s everything”: Maryland men’s basketball is quickly forming a defensive identity]

Saturday was an “ugly” game, as Underwood described it. Cowan’s heroics came on a busted play: an inbounds pass to guard Eric Ayala, a screen from Smith that didn’t work, a pass that got tipped and corralled once more by Smith. Finally, the ball reached Cowan.

He swished his deep attempt, then nailed the winning free throw with two seconds left.

“I feel like if you look at a real, Division I basketball game, high-major game, down the stretch, there’s really no playcalling,” Dosunmu said. “Each team knows what’s coming, it’s all about the players making plays. We just missed some and they made a good one.”

After Wednesday night’s 21-point victory over Notre Dame, Ayala was asked for the umpteenth time how Maryland can flip a switch, seemingly resurrecting a stagnant offense with a flurry of scoring.

“It’s just a matter of time before everything just starts clicking,” Ayala said.

It may have taken longer than normal Saturday. But the Terps did it, their players made plays, ensuring coach Mark Turgeon’s team remained undefeated for at least another game.