Adam Rooney converted a 34th-minute penalty to give Caley Thistle the lead after Grant Munro had been fouled in the box in an off-the-ball incident.
The Dons battled back and substitute Andrius Velicka, who had replaced the injured Darren Mackie, showed great composure in slotting the ball past the advancing Ryan Esson five minutes after the break.
However, with nine minutes remaining Munro headed home Richie Foran's cross to defeat the Dons.
The result preserves Terry Butcher's side's year-long unbeaten away run but may have severe repercussions for McGhee, whose team have now picked up only four points from the last possible 30.
The visitors dominated the early stages against a nervous Aberdeen and should have taken the lead after only eight minutes when the unmarked Rooney headed wide from an inswinging Jonny Hayes corner.
The Dons were struggling to maintain possession although Chris Maguire did have the opportunity to test Esson from distance after 12 minutes, but his weak effort sliced wide of the target.
Only a superb save from Jamie Langfield prevented the Dons falling behind two minutes later after Irishman Rooney's glancing header from Stuart Duff's cross looked certain to find the corner of the net.
At the other end Scott Vernon combined with Mackie to give himself a sight of goal but Esson managed to claw away the former Colchester striker's left-foot shot.
The Dons should have broken the deadlock after 28 minutes but Vernon failed to direct his header on target from Mackie's enticing cross.
Stand-in captain Zander Diamond was next to produce an inviting delivery into the box a minute later with Rory McArdle's downward header kept out brilliantly by Esson.
But just as Aberdeen began to settle they fell behind in controversial circumstances after 34 minutes.
A Duff free-kick appeared to be drifting harmlessly to safety when Munro fell in the box after colliding with a Dons defender in an off-the-ball incident and referee John McKendrick pointed to the spot. Mackie and Diamond were cautioned for their protests before Rooney coolly slotted the ball past Langfield from 12 yards.
The Dons were dealt a further blow when Mackie suffered a serious-looking injury after a collision with Caley stopper Esson and was replaced by on-loan Rangers striker Velicka just before the interval.
Aberdeen made a determined start to the second half and substitute Velicka should have equalised within four minutes but the Lithuanian headed over from a pinpoint Sone Aluko free-kick.
However the on-loan Rangers striker got the Dons back on level terms a minute later when, after being played in one-on-one by Vernon, he calmly knocked the ball past the advancing Esson and into the net.
The Dons were forced to make a second change after 57 minutes when youngster Ryan Jack suffered an injury and was replaced by Jerel Ifil.
The home supporters were appealing for a penalty when Derek Young's powerful drive from the edge of the area looked to have deflected off the arm of a Caley defender but referee McKendrick waved play on.
The visitors were looking increasingly dangerous as the game wore on and a terrific cross by full-back Kevin McCann was turned inches over the crossbar by the outstretched leg of Nick Ross.
With 15 minutes remaining Aluko burst to life as he collected Ifil's deep cross and produced a neat turn to gain a yard of space before unleashing a right-foot shot which just drifted past the post.
However with just nine minutes to go Caley scored what proved to be the winner when Foran crossed for Munro to head from 12 yards past the diving Langfield.
The Dons surged forward in search of a second equaliser but Caley held on for victory in what could turn out to be McGhee's final match in charge of the Dons.