STATE COLLEGE, Pa. – Penn State had the entire bye week to put its bitter loss to Ohio State in the rearview mirror. It began the week with what head coach James Franklin called "our best practice since we've been here." It felt it could be successful against a Michigan State pass defense that statistically was one of the worst in the nation.

Things didn't go well, however. The Nittany Lions' offense sputtered Saturday in the second half. Their defense played gallantly, but the weight of 89 offensive plays and more than 34 minutes in time of possession by the Spartans finally crushed them at the end.

A 25-yard touchdown pass from Brian Lewerke to Felton Davis III with 19 seconds remaining proved to be the difference, stunning the Beaver Stadium crowd of 106,685 and sending the eighth-ranked Lions to their second straight defeat, a 21-17 decision that pretty much ended any College Football Playoff dream they might have had.

Penn State (4-2, 1-2 Big Ten) suffered its first back-to-back defeats at home since 2014 and saw its string of 28 consecutive games of scoring at least 20 points go by the wayside. The Nittany Lions lost for just the fifth time in their last 29 games, and, in every one of those defeats, they have blown a fourth-quarter lead.

"We've lost some late in the last two, there's no doubt about it," a subdued Franklin said afterward. "But for every one that you've shown me that we've lost, I can show you example after example of ones that we've won like that. Obviously, all you can focus on right now is the present.

"What happened out there today, I get that, we've got to be able to finish. We've got to be able to finish on offense, defense, special teams, all three phases, and we didn't do that today."

Miles Sanders contributed to the Lions' touchdowns, both of them coming in the first half. He set up the first by dashing 78 yards and scored the second from 48 yards out, finishing with 162 yards in 17 carries against the nation's No. 1 rush defense.

But the Nittany Lions managed just three points in the second half. After the Spartans (4-2, 2-1) failed on a fake field goal try with 5 minutes, 19 seconds to play, the Lions were unable to work the clock, holding the ball for a total of just 1:37 on their last two possessions.

Penn State was unable to take deep shots downfield, with Trace McSorley's longest completion being just 25 yards. In finishing 19 of 32 for 192 yards and a touchdown, McSorley broke Christian Hackenberg's program record for career passing yards, finishing the game with 8,610.

However, he was hard on himself in his talk with reporters.

"I wasn't accurate enough, that's first and foremost," said McSorley, who threw a 5-yard scoring pass to K.J. Hamler. "I didn't execute right. I didn't do enough of a good job today to get the job done in the passing game, so that's on me. I've got to be better."

Freshman Jake Pinegar, who missed a 37-yard third-quarter field goal attempt that clanged off the right upright, kicked a 20-yard field goal with 9:21 left in the fourth to give the Lions a 17-14 lead but his team could not add to the margin.

Beginning its winning drive at its 24 with 1:19 left, Michigan State needed just 1 minute to go 76 yards in eight plays, and was so effective that it didn't need to call the one timeout it had available.

On the final play, Lewerke make a nifty back-shoulder throw down the left sideline for the touchdown to Davis, who was matched up one-on-one for much of the game with Amani Oruwariye, the Lions' best cornerback. Oruwariye, who dropped a sure interception on the second play of the drive, lay on the turf in anguish after the score and had to be helped up by his teammates.

There were other errors in the game. After Penn State stopped Michigan State on three straight cracks into the line from the 1 in the second quarter, an unsportsmanlike conduct penalty against defensive tackle C.J. Thorpe gave the Spartans a first down, and they cashed in for a TD on the next play.

"Overall, we have to give Michigan State credit," Franklin said. "We didn't do what we needed to do to win the game."