WEST LAFAYETTE, Ind. -- Michigan State coach Mark Dantonio likes his team's resilience.

Now it's time to develop a knockout punch.

Connor Cook threw three touchdown passes and Nick Hill ran for two scores Saturday, but No. 8 Michigan State still needed a late interception return for a touchdown to hold on 45-31 at Purdue.

"When you look at our football games, we're playing well enough to get up by 21 points, and that's the first thing you have to be able to do," Dantonio said. "When they come back, we somehow find a way at the end. I think that it makes us a stronger football team."

It's not supposed to be this difficult for the Spartans (5-1, 2-0), who have been the best team in the Big Ten over the past two seasons.

One week ago, they nearly blew a 24-point fourth-quarter lead at home against Nebraska before surviving 27-22. This time, the defending Rose Bowl champs saw a seemingly safe 21-point fourth-quarter lead nearly disappear because of a defensive breakdown that led to one Purdue touchdown and a failed fake punt that the Boilermakers converted into another score.

Purdue (3-4, 1-1) even got the ball back at its own 5-yard line with 2:57 to go and a chance to force overtime, but Darien Harris picked off an Austin Appleby pass and ran it back 15 yards to seal the win.

The Spartans have won four straight overall and seven straight conference road games, and tied the school record with a sixth straight win in this series. They also have 12 straight Big Ten wins, including last season's conference championship game, and remain the Big Ten's best hope of making the inaugural college football playoff.

Merely surviving won't be good enough.

"We didn't finish the way we wanted to," center Connor Kruse said. "I think there were a couple of calls and a couple of mistakes that we need to work on personally, offensively and defensively, and we are going to work on that this week."

Michigan State's offense certainly did its part.

It amassed 532 total yards, had 17 plays of 10 or more yards, scored five touchdowns and didn't punt until there was 1:10 to go in the third quarter.

When Purdue closed to 24-17 at halftime, the Spartans responded with touchdowns on their next two drives -- getting a terrific toe tap in the back of the end zone for a 13-yard TD catch by Aaron Burbridge. Hill followed that with a 4-yard TD run to make it 38-17.

"The defense obviously wasn't good enough. We didn't get the stops," Purdue defensive end Ryan Russell said. "Starting out slow, spotting a good team 21 points, you're not going to win like that."

Cook finished 19-of-37 for 238 yards with the three scores and one interception. Jeremy Langford ran 13 times for 104 yards, his third straight 100-yard game. Hill had nine carries for 72 yards and matched his career high with two scores. And Tony Lippett finished with seven receptions for 138 yards and one score.

But the Boilermakers' improved offense kept poking holes in the Spartans' vaunted defense.

After rallying from a double-digit deficit in the first half to make it 24-17 at halftime, then falling into a 38-17 hole after three quarters, Purdue rallied again.

Akeem Hunt's 52-yard scoring run with 8:49 left closed the deficit to 38-24.

The inexplicable fake punt then gave Purdue the ball at Michigan State's 30-yard line with 7:31 left, and three plays later, Hunt powered in from 3 yards out to make it 38-31.

The defense then forced a punt, giving Appleby a chance to pull off Purdue's biggest win in years.

Appleby finished 24-of-37 for 211 yards with one touchdown and one interception in his second career start. Hunt ran 12 times for 96 yards and three scores. Danny Anthrop had a career-high nine catches for 133 yards.

"Anytime the defense or the special teams makes a stop or makes a play for us, it's huge and it gives us a lot of momentum," Appleby said.

But Appleby's errant pass with 1:22 to play ended the comeback bid and allowed the Spartans to survive again.