EAST LANSING, Mich. (AP) - Bret Bielema was beginning to look ahead to overtime, and it was hard to blame the Wisconsin coach. Michigan State was out of field goal range and had time only for a long throw to the end zone.

"It's kind of one of those things where all of the stars have to be aligned for it to happen," Bielema said.

Well, it happened.

The fourth-ranked Badgers fell from the ranks of the unbeaten in stunning fashion Saturday night when Keith Nichol caught a 44-yard desperation heave from Kirk Cousins on the game's final play for a touchdown, giving No. 15 Michigan State a 37-31 win. With 4 seconds left, Cousins rolled out to his right and threw the ball about as far as he could. It went into the end zone but caromed off Michigan State receiver B.J. Cunningham's facemask back to Nichol, who caught it just outside the end zone and struggled for the goal line, fighting two Wisconsin defenders and just barely breaking the plane.

The former backup quarterback was initially ruled short of the end zone, but officials overturned the call after a review, giving the Spartans (6-1, 3-0 Big Ten) the win.

"The quarterback threw it up high, and all I know is Nichol came up with the ball at the end," Wisconsin defensive back Marcus Cromartie said. "I was in the end zone. It looked like a long play but it definitely happened fast."

Russell Wilson had led the Badgers (6-1, 2-1) from 14 points down in the fourth quarter to tie the game with 1:26 left on a to 2-yard touchdown pass to Montee Ball.

The wild game - in which both teams blew two-touchdown leads - featured an even more memorable finish. Wisconsin trailed 31-17 in the fourth quarter before Wilson ran 22 yards for a touchdown and made several spectacular throws on the move to set up the TD pass to Ball to tie it at 31.

Michigan State then survived a harrowing moment when Cousins fumbled deep in Spartan territory. Offensive lineman Dan France fell on the ball with 42 seconds left.

At that point, Wisconsin was eager to use timeouts, trying to get the ball back, but on second-and-20 from his own 24, Cousins found Cunningham for a 12-yard gain. The Spartans then picked up a first down on an 11-yard shovel pass to Keshawn Martin.

"If we get the ball back with less than 30 seconds we were going to go for a block (punt)," Wisconsin coach Bret Bielema said. "We were going for the win."

The drive appeared to stall at the Wisconsin 44, but the Spartans had time for one more play - one that will go down in Michigan State history along with last year's fake field that beat Notre Dame in another extraordinary night game at Spartan Stadium.

Cousins was able to buy enough time for receivers to get down the field. Cunningham was in the end zone, and the ball bounced off his helmet and into Nichol's arms. After Nichol caught the pass, Michigan State players immediately started spilling onto the field, even though officials ruled that Wisconsin's Mike Taylor had stopped him short. When the call was reversed and a touchdown was awarded, the celebration began again.

"We knew we had a chance," Cousins said. "There's always a chance."

Wisconsin had won its first six games of the season, all by at least 31 points. The Badgers entered the game leading the nation in scoring offense, and Michigan State was ranked second in total defense.

Michigan State handed Wisconsin its only loss of the regular season last year, but the Badgers went to the Rose Bowl anyway, emerging from a three-way tiebreaker with the Spartans and Ohio State atop the Big Ten.

Michigan State looked overmatched early on Saturday, allowing a pair of first-quarter touchdowns and struggling to hold off Wisconsin's powerful offensive line. The Spartans turned the game around in the second quarter with some impressive work on special teams.

Mike Sadler's nice punt pinned Wisconsin back at its own 5-yard line, and two plays later, Wilson threw the ball away under pressure in the end zone for an intentional grounding call and a safety that made it 14-2.

Michigan State scored its first touchdown on a slow-developing reverse. Martin avoided a tackler in the backfield and found running room to the outside for a 34-yard scoring run.

Wisconsin responded with an impressive drive but ended up settling for a 30-yard field goal attempt on fourth-and-1. Darqueze Dennard blocked it, and the Spartans capitalized with an 80-yard scoring drive. Cousins found Cunningham over the middle on fourth-and-2, and the senior receiver turned it into a 35-yard touchdown, giving Michigan State a 16-14 lead with 1:20 left in the half.

The Spartans weren't done. They used timeouts to stop the clock and forced a punt, which Kyler Elsworth blocked. The ball bounced back to the end zone, where Michigan State's Bennie Fowler was credited with the recovery amid a pile of bodies with 37 seconds to play.

After a Wisconsin field goal in the third quarter, Michigan State made it 31-17 when Cousins threw over the middle to Martin, who outran the defense to the sideline and turned up the field to the end zone for a 15-yard touchdown. Cousins then threw to Cunningham for a 2-point conversion.

Wisconsin missed a chance for a big play when Wilson's deep pass was dropped by Jared Abbrederis, but the Badgers later scored when Wilson scrambled to his right, faked out safety Isaiah Lewis with a pump fake and ran up the sideline for a touchdown that made it 31-24.

Michigan State won despite playing without defensive lineman William Gholston, who was suspended for a game after he was shown on video taking a swing at a Michigan player last weekend. The Spartans managed to sack Wilson three times - he'd been sacked only five times in the first six games.

Michigan State wasn't flagged for a single penalty against Wisconsin.

Wisconsin entered the night on a nine-game Big Ten winning streak, and the Badgers looked the part early, driving 80 yards in 11 plays on a clinical opening drive and taking a 7-0 lead on a 9-yard touchdown pass from Wilson to Jacob Pedersen.

Edwin Baker fumbled the ball back to Wisconsin on Michigan State's first play from scrimmage, and Ball scored on a 9-yard run that momentarily quieted the Homecoming crowd at Spartan Stadium.