IOWA CITY — The Iowa basketball team didn’t get that astonishing, head-turning, season-reversing victory it was hoping for Tuesday night.

But it couldn’t have possibly come closer.

The Hawkeyes opened an 8-point lead on No. 4-ranked Michigan State in the second half but couldn’t quite make enough plays in the last two minutes to complete the upset, going down to a 96-93 loss to the Spartans at Carver-Hawkeye Arena.

Nicholas Baer’s potential game-tying shot from halfcourt at the final buzzer ticked off the front rim to allow the Spartans (23-3, 11-2 Big Ten) to escape.

Miles Bridges, who led Michigan State with 25 points, had stolen an inbounds pass to seemingly secure the win for the Spartans a few seconds earlier. But Bridges, who leads the Big Ten in free throw shooting, missed two foul shots with 3.6 seconds remaining to leave the door open for a possible Iowa win.

The Hawkeyes (12-14, 3-10 Big Ten) trailed for much of the game before a second-half charge that included big plays by Tyler Cook, Jordan Bohannon, Cordell Pemsl, Isaiah Moss and Maishe Dailey, propelled them into an 81-73 lead with eight minutes left.

The Spartans slowly chipped away at the deficit and finally reclaimed the lead on a 3-point field goal by Kenny Goins with 2 minutes, 10 seconds to go. It was only the third 3 of Goins’ college career.

Cook, who led Iowa with 26 points, scored inside to reclaim the lead and Nicholas Baer blocked a shot by Cassius Winston but Winston batted away a 3-point try by Bohannon.

Bridges made two free throws with 1:02 remaining and two more with 31 seconds left, following a shot clock violation on the Hawkeyes. That made it 94-91.

Cook countered with another basket but Joshua Langford made two free throws for Michigan State with 6.3 seconds left

In addition to Cook;s big night, Iowa got 17 points, five rebounds and six assists from Jordan Bohannon. Dailey added 13 points and Moss and Pemsl 11 apiece.

Nick Ward added 17 points for the Spartans with Langford contributing 15 and Jaren Jackson 11.

Iowa shot 52.2 percent from the field in the game but continued to struggle at the defensive end of the floor. The Spartans shot 56.1 percent.

The Hawkeyes had trailed by 10 or more points at halftime in seven of the previous 10 games and it looked as though they were headed that way again as Michigan State got three dunks in the first minute-and-a-half and jumped to a 10-2 lead.

But Bohannon, who was plagued by the flu in a loss to Penn State on Saturday, brought Iowa back. His 3-point field goal with 8:35 remaining in the half briefly tied the score at 26-26 before Bridges knocked down a 3 of his own at the other end.

A pair of 3s by Matt McQuaid later in the half pushed the Spartans’ lead to 48-42 at halftime.

Moss, who had a quiet first half, got rolling early in the second half, scoring seven quick points. His fast-break dunk just 2½ minutes into the half sliced the Michigan State lead to 55-53 and a Luka Garza 10-foot jumper chopped it to a single point at 56-55.

The Hawkeyes finally tied the score at 60-60 on a Cook dunk off a pass from Moss and took their first lead seconds later on a Moss free throw.

After the lead bounced back and forth for a few minutes, Cook led a fast break that ended with a Bohannon 3-pointer to give the Hawkeyes a 68-64 advantage with 12:24 remaining.

That prompted Michigan State to call a timeout and the Hawkeyes kept rolling, getting contributions from some of their bench players. Cordell Pemsl scored on three straight trips down the court, Dailey drained a 3 and Nicholas Baer scored in transition to force the Spartans to call another timeout.

The lead peaked at 81-73 with 8:06 before Michigan State began a gradual comeback that included 3-pointers by Jackson and Winston.