The Dark Blues, who remain 14 points adrift at the foot of the table, had looked on course to follow up their midweek win over St Mirren thanks to a 13th-minute goal from John Baird until McKay struck with seven minutes remaining.
Inverness started brightly with McKay spurning an early chance when he headed wide.
But the home side broke the deadlock in the 13th minute when Davide Grassi and Brian Easton combined well before Ryan Conroy teed up Baird to net with an unstoppable finish from just inside the area.
Nicky Riley's powerful 20-yard shot then went just over for Dundee before Caley were dramatically denied an equaliser when Gary Irvine nodded Gary Warren's header off the line before Iain Davidson cleared the danger.
Andrew Shinnie also went close to levelling for the visitors as he smashed a shot against the crossbar, although Baird then almost made it 2-0 when he was foiled by a point-blank save from Ryan Esson.
Andrew Shinnie fired wide before the break, but Dundee took command after the restart with a lengthy spell of pressure culminating in Esson tipping over Davidson's flicked header.
McAlister was then played in by Baird but the ball became stuck in his feet and the Caley defence were able to clear.
Inverness then went close when Rab Douglas tipped Owain Tudur Jones' effort around the post and the Dundee keeper then safely gathered David Raven's header.
However Douglas was unable to prevent McKay from finding the net when he headed home Graeme Shinnie's centre from close range.