A performance short on quality from the Dons was redeemed by showing big character late in the day, Aberdeen moving into the last eight of the competition, chiselling out a 2-1 win after salvaging the game at the death at Dens Park.
With the Dons looking to get back to winning ways, Derek McInnes made just one enforced change to the side that were beaten by HNK Rijeka, Craig Bryson making his first start for the club, replacing the suspended Lewis Ferguson in midfield. Hosts Dundee made two changes from their 1-0 win over Ayr eight days previously, Josh Todd and Shaun Byrne replacing Kane Hemmings and Paul McGowan.
Niall McGinn created the first bit of excitement in the third minute, his shot blocked away for a corner after good work down the left involving Greg Leigh and Jon Gallagher. It was an encouraging opening from the Dons, looking for a goal after drawing three consecutive blanks.
The hosts picked it up from there and began to pen the Dons in, peppering them with long balls forward, looking to feed off second balls, though Scott McKenna and Andy Considine in particular handled the aerial bombardment well.
Sam Cosgrove went in the book on the quarter hour, catching Kerr in the face with a leading arm, though it looked purely accidental. From the free-kick, a long ball in saw a clever header into the box from Forster, Lewis scrambling it away, then the ball came back in from the left from McDaid, arcing through the box and giving Todd a free header at the back stick but somehow, he put his effort wide.
With the home crowd lifted, the Dons were struggling to get any sustained possession, confidence looking low after the recent run of defeats. Dundee were almost in front on 23 minutes, a superb turn on the edge of the box from Johnson culminating in a powerful shot that flew past Lewis but, fortunately, cannoned back into play off the post.
There were loud home claims for a penalty in the 35th minute, the Dark Blues arguing that Funso Ojo had handled a ball in but from there, the Dons broke quickly to force a corner at the other end. A second swiftly followed, but the danger was snuffed out by the referee's whistle - five corners from the Dons thus far that had amounted to little, if any threat.
Dundee boss James McPake took a long lecture from referee Collum on 39 minutes after some exuberant complaining but it didn't distract his side, Todd breaking down the right and arrowing a cross all the way through the six yard box without anyone getting the vital touch. Dundee were pressing the Dons energetically all over the pitch, giving them no time to play.
The Dons had almost got to the break unscathed but on 43 minutes, a coming together between Considine and Forster from a long ball into the box resulted in a penalty and a card for Considine, both decisions looking a little harsh. Johnson stepped up to the 12 yard mark and sent Lewis the wrong way to give his side a lead that, in truth, they deserved on the balance of the first half.
HALF-TIME: Dundee 1 Aberdeen 0
The Dons finally carved out a real chance in the 49th minute, Gallagher pulling the ball across goal from the right, Cosgrove stabbing the ball wide from 10 yards out. Dundee responded immediately, Byrne darting forward to the edge of the box before pulling his effort wide, Bryson booked for a foul in the build up.
Symptomatic of the day the Dons were having, Lewis spilled a routine cross in the 52nd minute as the Aberdeen side simply could not got anything going against a Dundee side buzzing around the pitch, Considine there to clear things up.
A bit of pressure was exerted a minute later, Ryan Hedges having a shot blocked, then Gallagher following up with a shot that lacked conviction, easily snaffled by Hamilton, early signs of much needed improvement, the Dons belatedly beginning to play more of their football in the opposition half.
Connor McLennan was introduced to the fray in the 57th minute, replacing McGinn after a quiet afternoon. Five minutes later, he was joined by Dean Campbell in place of Bryson while Dundee replaced goalscorer Johnson with Nelson.
Nelson quickly caused havoc, chasing down Considine in the 64th minute, Lewis swiftly off his line to clear. Derek McInnes made his final change in the 65th minute, James Wilson on for Hedges.
McLennan was beginning to cause problems for Dundee and in the 72nd minute, his cross found Leigh, his header looping up for Hamilton to claim. A couple of minutes later, the hosts replaced Ness with McGowan.
It was Dundee who threatened next, Kerr's shot from the edge of the box straight at Lewis in the 76th minute. McDaid then flashed a shot over the bar from distance as the Dark Blues began to exert control again. Logan collected a card 12 minutes from time as he ended another Nelson run. McDaid followed him into the book for hauling down McLennan on the charge. From the free-kick on halfway, it was all too easy for Hamilton to come off his line and claim, another poor set play from the Dons.
Good play from the Dons finally opened Dundee up in the 83rd minute, Ojo finding McLennan who darted into the box, his shot deflected up into the centre of the penalty area where Gallagher produced a fine diving header, only to see the ball hooked clear off the line by Forster.
Into the last five minutes, Meekings replaced Todd as Dundee looked to see out the game. With the Dons raising a gallop in the dying moments, a good ball in from Leigh caused havoc, Hamilton flapping at it but getting enough of a touch on it to push the ball clear.
A foul on Ojo brought Forster a yellow card as the game entered time added on and from the free-kick, the Dons saved themselves. It was Ojo's ball in, Cosgrove heading across to Leigh. His header was superbly clawed away by Hamilton but Gallagher was swiftly onto it, squaring the ball for Considine to slot in the equaliser from inside the six yard box.
The sides exchanged corners in the dying seconds, but onwards the game went to extra-time.
FULL-TIME: Dundee 1 Aberdeen 1
Two minutes into extra-time, McLennan's corner caused some consternation, Hamilton missing it, Considine heading over at the back post. McLennan looked much the most likely Don to make something happen, a driving 60 yard run in the 93rd minute leaving defenders in his wake, but his shot from 20 yards flew well over.
Robertson was replaced by Moore in the 98th minute as Dundee made their additional extra-time change. The game had turned now, Aberdeen keeping Dundee penned in their half, Wilson trying his luck from distance in the 99th minute, pulling his effort well wide.
In the 103rd minute, the Dons were finally ahead. Good work between Leigh and McKenna down the left hand side ended with the left-back hitting the by-line and putting in a nice cross to around the penalty spot, Cosgrove getting up well to head the ball back across goal and inside the far post with Hamilton left flat footed.
EXTRA-TIME HALF-TIME: Dundee 1 Aberdeen 2
A horrible, entirely accidental, collision in mid-air between Wilson and Forster had both medical teams on the park early in the second half administering treatment. Forster was relatively quickly on his feet but Wilson stayed down considerably longer before gingerly getting to his feet and continuing.
The tiring hosts were looking for a way back in, McDaid driving the ball straight at Lewis, then moments later, Lewis fell awkwardly in collecting the ball, needing treatment, just as he had done against Rijeka on Thursday before he too continued.
The Dons could have made the tie safe after 114 minutes, a good ball in from Logan reaching Cosgrove but he scuffed his first time effort wide of goal. What looked like a foul throw from Nelson at the other end caused hearts to flutter in the Dons defence a minute later, Lewis quickly out to punch clear and then gather of Considine. Nelson tried it again with another throw a minute later, hurling the ball into the welcoming arms of the Dons' captain.
A scramble in the Dons' box was eventually cleared by Campbell as the hosts tested Aberdeen nerves by throwing everyone forward in the 118th minute and a minute later, Gallagher was replaced by Zak Vyner in Aberdeen's fourth switch.
Great goalkeeping from Lewis calmed things down in the first of four added minutes, dashing 15 yards off his line to catch another long free-kick launched into the Aberdeen box and ease the pressure.
Still Dundee came, Marshall's chipped cross into the box pushed behind for a corner by Lewis, Hamilton joining his colleagues in the box, Marshall snatching at his shot as the ball dropped for him and ballooning the ball over.
And that was that, the Dons squeezing through to earn a third round trip to Tynecastle. In cup football, it's all about the result.