Abdessalam Benjelloun came off the bench to score two goals in nine minutes as Hibernian came from behind to oust Aberdeen from the Scottish Cup.
Michael Stewart put Hibs ahead against Aberdeen
Barry Nicholson had fired the Dons into an early replay lead following a fine through ball from Steve Lovell.
But a Steven Fletcher header and a superb Michael Stewart volley following Dean Shiels corners put Hibs in the driving seat by half-time.
And sub Benjelloun weaved his way to a double to secure a tie with Gretna.
Hibs had made four changes for the third-round tie, former captain Kevin Thomson dropping out along with Kevin McCann, Ross Campbell and the injured David Murphy.
Stewart - free from suspension - started along with Steven Whittaker, Ivan Sproule and Guillaume Beuzelin.
Aberdeen were without injured veteran striker Craig Brewster, so Lovell was preferred to Lee Miller up front.
But the early action was at the other end, with Beuzelin, Rob Jones and Scott Brown all threatening the Dons goal.
Aberdeen ought to have taken the lead when Darren Mackie broke clear and Lovell failed to get a touch on the perfectly-placed low cross to the front post.
But the striker made up for that moments later when he played a neat one-two on the edge of the box with Nicholson, who neatly placed the ball past goalkeeper Andrew McNeil.
The lead lasted less than three minutes, Fletcher rising above Andrew Considine to loop a header into the net.
Barry Nicholson (left) put Aberdeen 1-0 up in Edinburgh
A Lewis Stevenson back pass forced McNeil to pick the ball up eight yards from Hibs' goal.
But the goalkeeper spared their blushes by holding Scott Severin's powerful drive from the resulting free-kick.
And Hibs edged in front when Stewart met a Shiels corner on the volley that looped just under the crossbar from 18 yards.
It was a blow to the Dons, but it was Hibs who made the surprise half-time changes, with Stewart, who had been feeling ill, and Shiels making way for Thomson and Benjelloun.
The switch paid off immediately after Sproule dispossessed Nicholson on the halfway line.
A Thomson pass found Fletcher, whose first-time flick-on put Benjelloun clear and the Moroccan rounded the goalkeeper to slot home Hibs' third goal.
Benjelloun then picked up a long kick from McNeil before teasing Considine and firing low under Langfield from the edge of the box.
Aberdeen hopes of a revival ended when Clark missed a great chance by blasting over an open goal after McNeil had blocked from Nicholson at point-blank range.
Hibernian: McNeil, Whittaker, Hogg, Jones, Stevenson, Beuzelin (McCann 75), Stewart (Thomson 46), Scott Brown, Shiels (Benjelloun 46), Fletcher, Sproule.
Subs Not Used: Simon Brown, Martis. Booked: Fletcher.
Goals: Fletcher 13, Stewart 45, Benjelloun 47, 56.
Aberdeen: Langfield, Hart, Anderson, Considine, Clark, Foster, Severin (Daniel Smith 70), Nicholson, Dempsey (Maguire 55), Lovell (Miller 64), Mackie.
Subs Not Used: Soutar, Winter.
Booked: Considine, Hart, Miller.
Goal: Nicholson 10.
Ref: C Thomson