McKay and Andrew Shinnie struck to put Caley Thistle three ahead inside 27 minutes but Motherwell had scored 15 goals in their five most recent games and 12 against Inverness in three previous meetings this season and they stormed back.
James McFadden hit two goals either side of Michael Higdon's penalty to draw Motherwell level in the 64th minute as they sought the point needed to secure second place.
They looked like they might take all three but Henrik Ojamaa was sent off and McKay atoned for an earlier penalty miss when he fired a close-range winner six minutes from time.
The victory keeps Inverness in pole position to join Motherwell in the Europa League and both sides showed why they deserve their current top-three positions for entertainment value alone.
Inverness, with Chris Hogg making his comeback after 18 months out with a knee injury and Owain Tudur Jones benched, had an unseasonably strong wind at their backs from kick-off and took just over three minutes to exploit their advantage.
Graeme Shinnie's 20-yard free-kick hit the wall but Aaron Doran retrieved the ball and lifted it over to Josh Meekings, who was in yards of space as the Motherwell defence looked in vain for an offside flag.
Meekings sent a low cross into the six-yard box and McKay got there first to stab home.
Motherwell soon had a penalty claim turned down by Willie Collum after Nicky Law went down under the close attention of Danny Devine after beating Inverness goalkeeper Antonio Reguero to Keith Lasley's through-ball.
But the home side were soon back on the front foot and Richie Foran hit the post after winning the ball and playing a one-two with Andrew Shinnie.
Caley Thistle were pressing Motherwell aggressively high up the park and the visitors survived some more nervous moments amid a succession of blocked shots. Inverness doubled their lead in the 25th minute after Motherwell failed to cope with a long free-kick from Meekings.
McKay held the ball up before Andrew Shinnie pounced on the loose ball 12 yards and guided a left-footed shot into the bottom corner.
The front pair combined again two minutes later. Shinnie ran clear on to Foran's ball down the right wing and had all the time he needed to pick out McKay who supplied another sliding near-post finish. It almost got worse before it got better for Motherwell as Doran was soon sent clean through but he hesitated after taking the ball round Randolph.
A stunned Motherwell got a goal back in the 36th minute when McFadden collected the ball from Ojamaa 20 yards out and swerved a powerful low drive with the outside of his boot into the bottom corner.
Motherwell almost pulled another one back inside the first minute of the restart when Higdon volleyed Tom Hateley's high cross inches wide.
They only had three more minutes to wait. Ojamaa ran on to Higdon's and got in front of Hogg, who was too close and took him down. Higdon sent Antonio Reguero.
Ojamaa got in front of Hogg moments later and went down again, this time just outside the box, but Collum booked him for diving.
The Estonian was soon played through twice in quick succession but Reguero was out sharply to foil him both times.
Motherwell were on top at this stage but they were caught on the break and Humphrey needlessly brought down Nick Ross, but McKay hit the resulting penalty too straight and Randolph saved.
Motherwell were level 60 seconds later after Inverness failed to defend a set-piece. Ojamaa stabbed the ball through for the unmarked McFadden and he finished in off the post.
Both sides soon had chances. Shaun Hutchinson and Randolph combined to deny McKay after Shinnie had played him in over the top and Law fired just over from 12 yards after Ojamaa had got in behind.
Yet another flashpoint came in the 73rd minute when Ojamaa stretched to tackle Andrew Shinnie after a heavy touch and was shown a second yellow card after getting there too late.
Motherwell appeared to be coping well with 10 men but McKay struck again in the 84th minute after Randolph had parried a powerful long-range strike by Meekings.
The visitors were not finished and piled bodies forward but the hosts survived.
- Sports & Recreation
- Andrew Shinnie
- Henrik Ojamaa
- Caley Thistle