Aberdeen came from behind to snatch victory over Livingston with a dramatic injury-time winner from youngster Jack MacKenzie.
Trailing to a first-half goal from former player Bruce Anderson, the Dons levelled things up early in the second half with a strike from on-loan Brighton midfielder Teddy Jenks.
And in the fourth minute of time added on, the Pittodrie outfit grabbed all three points when 21-year-old MacKenzie struck to seal a 2-1 win.
The goal was calamitous for Livingston goalkeeper Max Stryjek, who allowed MacKenzie’s shot to slip through his grasp and over the line to spark a pitch invasion from the visiting fans that could get Aberdeen into trouble.
The teams traded opportunities in the opening exchanges as both sought the early ascendancy.
With just two minutes on the clock, Livi striker Alan Forrest fed James Penrice, who speared in a low cross, but Anderson could only knock his shot wide of the upright from close range.
In the 14th minute, it was Aberdeen’s turn to threaten. Jason Holt was slack with a pass in the heart of the pitch and Jay Emmanuel-Thomas pounced to play in Ryan Hedges. The attacker drove at the home defence but sent his eventual effort marginally over the crossbar.
Livingston looked more threatening and eventually made the breakthrough 10 minutes before the interval.
Craig Sibbald’s corner from the left was only half-cleared by Aberdeen and Penrice headed back into a crowded box. Joe Lewis came for the high ball but Anderson reached it first and looped his header over the stranded goalkeeper and into the empty net.
It could have been two for Livingston just six minutes later after Anderson raced onto a Jackson Longridge through ball and brilliantly picked out the supporting Scott Pittman, but the midfielder tamely shot too straight at Lewis.
Aberdeen regrouped at the interval and emerged with more energy, and were instantly rewarded with a 47th-minute equaliser.
A sustained period of possession concluded with a Niall McGinn cross that was only partially by Longridge. It was seized on by Jenks and he drilled his shot beyond the dive of Stryjek.
The equaliser injected more urgency into the visitors and they almost gained the lead six minutes later.
MacKenzie’s free-kick picked out Declan Gallagher but Sibbald cleared the Scotland defender’s header off the line.
Moments later, it was Livingston who came close to the next goal as Forrest’s corner from the right was headed in by Ayo Obileye, but Hedges booted clear from under his own crossbar.
The match swung from end to end thereafter buy it was Aberdeen who snatched the victory with just seconds remaining when MacKenzie’s shot dropped over the line.