Two goals in the final three minutes prevented Aberdeen from securing a UEFA Cup place for next season as Hearts staged a late comeback at Pittodrie.
Jambos defender Andy Tod had taken advantage of an error by debutant Dons goalkeeper Mark Peat to open the scoring in the third minute.
But Kevin Rutkiewicz hit back for the home side just five minutes later and striker Robbie Winters appeared to have hit the winner with 11 minutes remaining.
However, the Edinburgh team refused to lie down and defender Stephane Mahe hit home with only three minutes of the game remaining.
Then, Hearts completed an amazing fightback when Kevin McKenna grabbed a last-gasp winner.
Danish goalkeeper Peter Kjaer had been ruled out through injury and his understudy David Preece injured a hand in training leaving the Dons to field blood 20-year-old reserve goalkeeper Peat.
But his early blunder did not inspire confidence.
Hearts broke up the left-hand side and launched a harmless looking ball into the Dons penalty area.
But Peat eagerly ventured out farther than he should have and missed a punch clearance, leaving Tod with the chance to loop the ball high over Phil McGuire and into the net.
However, the Dons did not hang their heads and were on level terms five minutes later.
A Winters’ free-kick floated towards the Hearts box and Rutkiewicz ran to the near post and connected with the ball sweetly, lofting it past Hearts goalkeeper Antti Niemi and Alan Maybury for the equaliser.
Darren Mackie wasted a golden opportunity with only two minutes remaining of the first half but credit must also go to goalkeeper Antti Niemi.
The young Scot broke down the left and appeared certain to score but ventured too far wide and allowed Niemi a better angle from which to make a low save.
After the re-start, Aberdeen began to dominate and were desperately unlucky not to have been awarded a penalty.
Kevin McNaughton ran 40 yards upfield with the ball, played a one-two with Leon Mike and broke into the Hearts area.
The Dons defender then tricked Mahe into making a tackle when he attempted an audacious drag-back. The Frenchman looked to have clipped McNaughton’s legs and he went down under the challenge.
However, referee Mike McCurry, who looked to have a perfect view of the incident, waved play on amid protests from the home players and fans.
But the Dons got the goal they deserved in the 79th minute, courtesy of a header from Winters.
Jamie McAllister picked up the ball on the left-hand side and whipped in a cross for Winters. The Aberdeen striker took advantage of some sloppy Hearts defending to head past Niemi from three yards.
The home side looked to have wrapped up all three points but contrived to throw the game away in the final two minutes.
Mackie wasted another golden opportunity to put the game beyond the visitors but looked on in horror as Hearts strode up the field to equalise.
Second-half substitute Thomas Flogel combined with Stephen Simmons to feed Mahe in the Dons’ area and the Frenchman blasted past Peat from 16 yards.
The Jambos then clinched all three points in spectacular style two minutes later through McKenna.
The Aberdeen players looked shocked at having blown their lead and they allowed the Canadian internationalist to ghost into their penalty area and head home unchallenged from six yards.
Aberdeen: Peat, McNaughton, McGuire, Rutkiewicz, McAllister, Derek Young, Darren Young, Bisconti, Winters, Mike (Dadi 72), Mackie. Subs Not Used: Hutton, Thornley, Clark, Tiernan.
Hearts: Niemi, Maybury, Tod, McKenna, Mahe, Boyack (Webster 82), Tomaschek (Flogel 71), Severin, Simmons, Fuller, Weir (Fulton 82). Subs Not Used: McKenzie, Wales.
Ref: M McCurry (Scotland).