Aberdeen substitute Scott Vernon snatched a dramatic 93rd-minute winner against Dunfermline to send the Dons into the fourth round of the Scottish Communities Cup.
The tie appeared destined to be heading to extra-time but the marksman bundled in Niall McGinn's teasing delivery with seconds left.
The visitors had been booed off at the interval following a first half dominated by the First Division side.
But after some resolute defending and fine goalkeeping from Jamie Langfield, Aberdeen snatched the win after a more competitive display after the break.
In a bright start to the match, both sides created chances that had their fans off their feet.
McGinn thought he had a clear sight of goal after running onto Jonny Hayes' deflected pass inside the box but Callum Morris made a great block tackle.
The hosts turned defence into attack within the blink of an eye and Stephen Husband had a shot from 15 yards parried by Langfield after Andy Barrowman cleverly dummied Andy Geggan's pass.
The sight of Josh Falkingham harrying and charging down an attempted Clark Robertson clearance was systematic of the Pars' approach to the game as their opponents kept the visitors on their toes.
The industrious Falkingham stabbed a loose ball to Ryan Wallace and the diminutive marksman spun past Robertson before dragging a right-footed shot just wide from inside the penalty area.
Wallace then came within inches of connecting with a teasing Joe Cardle through-ball but the ball bounced into the arms of Langfield.
A wild Gavin Rae swing on a Robertson cross that was sliced hopelessly wide summed up the Pittodrie side's first half.
The Dons survived penalty appeals in the 37th minute when referee John Beaton decided that Rae's trip on Cardle was just outside the box. Cardle took the free-kick but his powerful drive cannoned off the wall.
Aberdeen created their best chance of the half four minutes before the interval when McGinn raced onto Cameron Smith's defence-splitting pass - but the former Celtic player hit a left-footed shot over the bar from close range.
An exciting finish to the first 45 minutes saw Barrowman crack a left-footed shot off the far post after Falkingham's deflected effort fell kindly at his feet.
The Dons made a more encouraging start to the second period but Paul Gallacher easily gathered Hayes' tame effort from close range following a Josh Magennis cross.
Cardle then beat right-back Magennis before curling a right-footed shot just round Langfield's far post from 20 yards.
The lively winger was then denied a speculator goal when Langfield palmed his long-range effort onto the bar.
Cardle was in the thick of the action and his corner caused panic in the goalmouth before the danger was eventually cleared.
Aberdeen brought on captain Russell Anderson at right-back for Magennis and the defender volleyed an Isaac Osbourne corner just wide in the 72nd minute.
Just as the game looked to be heading to extra-time, substitute Vernon bundled in a McGinn cross inside the six-yard box to carry the visitors through.