– Wisconsin interim men's basketball coach Greg Gard likes to say experience is a great teacher.

Maybe, then, the Badgers have learned something after coming up just short in games against the likes of Maryland, Indiana and Marquette.

Whereas they fumbled away late opportunities in recent close losses, this time Ethan Happ scored underneath with 10 seconds left as the Badgers beat No. 4 Michigan State 77-76 on Sunday.

Wisconsin's four Big Ten losses are by an average of 3.75 points, including a painful 63-60 home loss to Maryland on Jan. 9, when Melo Trimble hit a last-second three-pointer.

"We were just a little bit better in each possession," said Gard, who beat a ranked team for the first time since taking over after Bo Ryan's sudden retirement last month. "Did we play any differently? No. We were still trying to do the same things."

The Badgers (10-9, 2-4 Big Ten) looked on the verge of letting another one slip away after Denzel Valentine hit a runner to put the Spartans (16-3, 3-3) up 76-72.

But Bronson Koenig, who scored 27 points, hit a three-pointer with Valentine in his face that pulled the Badgers to 76-75 with 27 seconds left.

The Badgers then went to a full-court press, and they forced a turnover as Eron Harris stepped out of bounds while double-teamed.

Koenig then found Happ underneath the basket. The 6-9 forward briefly bobbled the ball in heavy traffic, spun out from underneath the hoop and hit the winning shot.

The Spartans had a final chance to win, but Valentine missed a three and Matt Costello's last-second side jumper bounced off the rim.

"We played together the whole 40 minutes, and it showed," said Happ, who had 14 points and eight rebounds.

Nigel Hayes scored 25 points for the Badgers, who went 29-for-36 on free throws. Michigan State was 12-for-16.

"It was hard to play," Spartans coach Tom Izzo said of the fouls. "But that had nothing to do with missing the five or six layups we missed."