WEST LAFAYETTE, Ind. (AP) — Michigan State coach Tom Izzo liked the way his team fought back Tuesday night.

It overcame a dismal first half. It rallied from an 18-point deficit to take the lead in the second half. It buckled down to tie the score late in overtime. And then the Spartans somehow let it get away.

Rapheal Davis made 1 of 2 free throws with 4.6 seconds left and A.J. Hammons wrestled the ball away from several defenders to give No. 18 Purdue a stunning 82-81 overtime win over the eighth-ranked Spartans.

"I didn't think we deserved to be 18 down. We took good enough shots in layups and dunks, but I thought Purdue outplayed us," Izzo said. "They made the plays down the stretch and tonight the better team won it. I can accept that."

The Spartans (20-5, 7-5 Big Ten) came into the game playing some of their best basketball all season.

But they sure didn't show it inside Mackey Arena, falling behind quickly in the first half and into a 48-30 deficit in the first minute of the second half.

Denzel Valentine was erratic, too. He ignited the comeback by making three 3-pointers in 49 seconds to get Michigan State within 50-44 with 16:02 left in regulation but only scored six points the rest of the game.

Michigan State's top player finished with 27 points, eight rebounds and 10 assists but missed a 3-pointer that could have won it at the end of regulation and committed the foul that sent Davis to the free throw line in the closing seconds of overtime, the kind of mistakes that made Izzo cringe.

"When you miss three dunks and lose by a point it's hard to stomach," Izzo said, one of those by Valentine.

The Boilermakers turned the game into an impromptu senior night celebration.

Davis, the defensive stopper, played the offensive game of his life. Hammons, the 7-foot center who patrols the post, nearly posted a triple-double. Together they refused to let Michigan State beat them for an eighth consecutive time.

So when Purdue's 18-point second-half lead vanished and Michigan State took a 72-68 lead with 1:59 left in regulation, Davis and Hammons wouldn't allow it to happen to them again.

"I've been telling these guys since the summer I just want to beat Michigan State," Davis said. "I've never beat Michigan State. Playing Michigan State is like playing IU (Indiana) for me. It's a little bit more than playing IU for me."

The Boilermakers (20-5, 8-4) scored the final four points of regulation and the first four points in overtime. Davis broke the 81-81 tie and Hammons sealed it with the rebound before spiking the ball and jogging to midcourt where the Purdue players embraced.

Davis needed just one half to produce a season-high 19 points and set a career high by making five 3-pointers. When the shooting guard cooled off in the second half, Hammons jumped in and finished the job. He scored 19 points, had a season-high 13 rebounds and eight blocks to equal a career high.

MAKING PROGRESS

For the second time in five weeks, the Boilermakers completely unraveled in the second half after dominating the first half. Against Iowa, Purdue blew a 17-point second half lead and wound up getting beat 70-63. On Tuesday, after blowing the 18-point lead, they found a way to fight back and hold on for the win.

LONG TIME COMING

The Spartans hadn't just been beating Purdue lately — they had blown them out. Purdue lost six of the seven previous games by double digits and hadn't beaten Michigan State since Feb. 27, 2011. It's also Purdue's first win over a top-10 team since they beat No. 2 Ohio State 76-63 on Feb. 2, 2011.

TIP-INS

Spartans: Michigan State started the night with the nation's most lopsided rebounding advantage (plus-12.8) but got outrebounded 42-39. ... Matt Costello blocked one shot to tie Drew Nymick (134) for No. 3 on the school's career list. Costello needs nine blocks to break Branden Dawson's school record (142).

Boilermakers: Caleb Swanigan, Indiana's reigning Mr. Basketball who originally committed to play for the Spartans, scored the final four points of regulation to force overtime and finished with eight points and four rebounds. ... Purdue is still the only Division I team that has outrebounded its opponent in every game this season.

UP NEXT

Michigan State hosts Indiana on Sunday.

Purdue visits Michigan on Saturday.