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, 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.

Despite the fact that it drops Iowa two games below .500 at and ensures that it will have a losing record in the Big Ten, it was hard not to see the game in a positive light.

“It’s definitely a positive,’’ Iowa coach Fran McCaffery said. “It shows the way we’re capable of playing.’’

“I’ll remember it as a testament to how good we can be, how well we can play, how hard we can play,’’ added sophomore forward Tyler Cook, who led the Hawkeyes with 26 points.

Forward Cordell Pemsl, who scored nine of his 11 points in the second half to help the Hawkeyes grab the lead, described the game as “awesome’’ and “a huge step.’’

“A lot of positive things from tonight,’’ Pemsl said. “Any time you’re up with two minutes to go against the fourth or fifth-ranked team in the country, you’re doing something right. Tonight, we definitely showed what kind of game we can play.’’

Michigan State coach Tom Izzo opened his postgame press conference with a one-word summation of the contest: “Wow.’’

“I hope you all enjoyed the offensive fireworks tonight,’’ he said. “I don’t think either team played any defense. I know we didn’t.’’

Izzo added that he thought Iowa was “as good an offensive team as we’ve played all season.’’

The Hawkeyes (12-14, 3-10 Big Ten) trailed for much of the game before a second-half charge that included big plays by Cook, Pemsl, Jordan Bohannon, 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 scored inside to reclaim the lead and Baer blocked a shot by Cassius Winston, but Winston then 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.

“Obviously it’s a tough one because we battled our butts off for 40 minutes,’’ said Bohannon, who again played with the flu but managed to provide 17 points, five rebounds and six assists. “It just sucks knowing how close we were to beating one of the top teams in the country, a probable Final Four team.’’

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 fell behind early as Michigan State got three dunks in the first minute-and-a-half and jumped to a 10-2 lead.

But Bohannon brought Iowa back, hitting a 3-point field goal with 8:35 remaining in the half that 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 in the first 2½ minutes, and the Hawkeyes finally tied the score at 60-60 on a Cook dunk off a pass from Moss, then 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. Pemsl scored on three straight trips down the court, Dailey drained a 3 and 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.

“It stings any time you lose a game,’’ Pemsl said. “Big picture, we played a helluva game tonight. I’m really proud of my brothers. We went to war tonight. Although it didn’t come out the way we wanted it to, it was a huge step for us.’’