Gardner, making his second start at quarterback in place of the injured Denard Robinson, completed 16-of-29 passes and connected for two touchdowns. His 53-yard bomb to Roy Roundtree in the closing seconds set up a game-tying field goal by Brendan Gibbons with 2 seconds left in regulation.
Gardner plunged in from 1 yard out in OT for his second rushing touchdown of the day.
The win gave Michigan (7-3, 5-1 Big Ten) its fifth win in six games and extended its home unbeaten streak to 13 games dating back to 2010.
Northwestern (7-3, 3-3) had grabbed a 31-28 lead with 3:59 to play in the fourth quarter, but had to punt after running seven plays on its final possession, giving Gardner the chance to tie the score on just three plays in the closing seconds.
The Wildcats needed a touchdown on their only possession in overtime but got no closer than the Michigan 17.
Kain Colter and Trevor Siemian combined for 183 passing yards and three touchdowns for the Wildcats. Venric Mark ran the ball 23 times for 104 yards and a touchdown.