Hearts were leading through Jamie Walker's 18th-minute strike before referee Alan Muir adjudged McHattie to have fouled Calvin Zola in the box midway through the second half and showed him a straight red card.
McHattie looked to have won the ball, although he had his hands on the Dons substitute, and Hearts looked to be in danger of losing another immediately after Niall McGinn converted the penalty.
But they rallied again and McGhee headed home at the back post in the 88th minute to cut the Edinburgh club's initial 15-point penalty further down to leave them on minus eight.
Aberdeen boss Derek McInnes and Hearts assistant manager Billy Brown were ordered off in the aftermath of the goal with the latter then involved in an angry exchange with Dons counterpart Tony Docherty.
The Dons were left to rue a wasteful first half when the recalled Scott Vernon failed to seriously trouble Jamie MacDonald despite being played through three times.
Vernon's first chance came three minutes in when Reynolds' clearing header sent him through as the Hearts defence looked for an offside flag, but the Englishman sent a weak left-footed shot straight at MacDonald.
Dylan McGowan and Reynolds had chances following set-pieces at either end but neither could get enough purchase on their headers.
Vernon was then played through by McGinn's sharp pass but got the ball caught between his feet.
Hearts were finding it difficult to get out of their own half but they caught the Dons on the break.
Jason Holt broke down the right and played the ball over to Walker on the left as he crossed the halfway line. The pass put right-back Joe Shaughnessy on the back foot and Walker cut inside him before firing low into the far corner from 18 yards.
Vernon should have levelled four minutes later when Nicky Weaver's goal kick beat the Hearts defence but he sliced wide from 16 yards.
The Dons gradually got back on top but could not take advantage of their first-half pressure. Robertson twice did well to met McGinn's cross well following a short-corner routine but headed off target both times.
Hearts created the first chance of the second half when Walker had a low shot blocked by the feet of Weaver.
Zola replaced Vernon in the 53rd minute and soon glanced a header wide from Jonny Hayes' cross.
Hearts lost Brad McKay to concussion and sent on McGhee at right-back with McGowan moving inside.
Robertson and Hearts midfielder Scott Robinson were booked as the game turned scrappy and Muir soon made a more significant decision.
McHattie had reacted quickly to foil Zola after a half-cleared corner was headed back into the box to put the forward through, and he was distraught at his red card.
McGinn sent his penalty high into the corner of the net before getting a yellow card for cupping his ears towards the Hearts fans.
Muir made another controversial decision when Peter Pawlett put the ball past Walker and went down under the midfielder's sliding challenge just inside the box. There looked to be contact but Pawlett, who has received several bans for simulation, was booked for diving.
The 10 men survived the initial Dons pressure before coming back into the game. Jamie Hamill volleyed not far wide from 22 yards after a wonderful sharp passing move and Calum Paterson was inches away from reaching substitute David Smith's cross in front of goal.
Aberdeen had a great chance to go in front when McGinn headed off the bar and over from six yards following Gregg Wylde's cross.
And they were made to pay moments later when Weaver missed Callum Tapping's deep free-kick under pressure to leave an open goal that the unmarked McGhee found from a tight angle.
Hearts survived five desperate minutes of injury-time with MacDonald saving brilliantly from Josh Magennis and Aberdeen having a penalty claim denied when Paterson and Zola tangled.