McKay put Caley Thistle in front after four minutes and Gary Warren doubled the lead two minutes later as the visitors appeared set to extend their unbeaten run to six at Dens Park.
Colin Nish pulled a goal back after 13 minutes, but Andrew Shinnie converted an 81st-minute penalty before laying on McKay's second as Terry Butcher's men climbed to third place in the standings.
The hosts have now lost five successive games to sit four points adrift in an otherwise tight SPL table.
Dundee boss Barry Smith welcomed Friday night football, but he may have wished for a quiet night in after his side made a dreadful start.
Nicky Riley, one of four changes for the hosts following the loss to Hibernian, flashed a shot wide, but 30 seconds later the hosts were behind.
Dundee delayed too long on the ball at the back and Neil McGregor's clearance was blocked.
The ball fell for Aaron Doran, whose shot was parried by Rab Douglas, leaving a simple tap-in for McKay, in for injured captain Richie Foran.
The shell-shocked hosts found themselves two down little more than a minute later. Again Doran was the provider, his free-kick from the left finding Warren to net from close range.
Riley blasted off target from an angle before the deficit was halved when Nish drilled a loose ball low under Antonio Reguero after Steven Milne's shot was blocked.
Doran continued to trouble Dundee down the right, with the hosts doing little to aid their cause by relinquishing possession all too easily.
Dundee finished the half on top and came close to an equaliser.
Davide Grassi curled a free-kick over the bar after a foul on Riley on the edge of the area.
A cross from Riley, who was troubling stand-in Inverness skipper Graeme Shinnie, almost crept through to Jim McAlister, but Reguero was swift off his line to spread himself and the danger was cleared.
Perhaps the best opportunity fell to Nish after Milne's run and cross from the right fell to the former Hibs striker, whose cleanly struck shot was well saved by Reguero.
Dundee resumed on the attack, with Matt Lockwood's cross flicked on by McAlister to Milne, who failed to find the target from six yards out.
Andrew Shinnie attempted to spark Inverness back to life and twice had opportunities to restore the two-goal lead, the second a curling effort from the edge of the area which went narrowly wide.
Another chance fell the visitors' way when on-loan Arsenal forward Philip Roberts latched on to a long ball down the left, cut inside and fired wide across goal.
Dundee pressed forward and Riley crossed into a dangerous area, but none of his team-mates were in a position to react.
Doran and over-lapping full-back David Raven combined to set up an opportunity for Andrew Shinnie, but the forward could not direct his header on target.
Dundee made a double substitution with 16 minutes remaining, pulling off left-back Lockwood and striker Milne, with attackers John Baird and Ryan Conroy brought on.
But it was an Inverness substitute who made an impact.
Shane Sutherland, who replaced Roberts after 64 minutes, crossed from the right to find Draper, whose first-time shot ricocheted down off the crossbar.
Sutherland was felled by a rash Iain Davidson challenge and Andrew Shinnie converted from the spot nine minutes from time.
Inverness struck again with five minutes remaining as Andrew Shinnie turned provider.
The playmaker ran at the heart of the Dundee defence and found McKay, who was composed enough to take his time before firing past Douglas to seal victory.