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.
"Today wasn't about playing well, we had some good performers second half but it was about digging deep and getting the result.
"Two weeks ago we left Pittodrie after beating Hearts 3-2 and everybody was euphoric, saying this was the best team we have had for a while, the best squad and we were so high then. What we have had over the last two or three games is a real low and it threatened to be that again today.
"I have just reminded the players that we can't go from being as high as that to as low as we feel, there has to be more inner confidence in us.
"Big Andy did well coming up from the back to recover from the penalty, I haven't seen it back but if he has conceded a penalty he has certainly made up for it. I thought the approach of the players from then, when it was a real dagger in the heart for Dundee, we looked like the team that would get the second goal.
"I felt a second goal coming and once we got it we managed to get over the line without too much fuss, Dundee gave us a tough game as we expected and we made it tougher for ourselves. But the cups are all about getting through and finding a way to win and today my players deserve so much praise for finding a way to win.
"Now we need to give a couple of days rest for the majority of them and get back to having proper training weeks and proper preparation for a game because we are in real need of some training days that we haven't had the luxury of.
"There has to be a strength, certainly at this club, to dig out results when you are not playing at your best. For long spells it didn't look as if there was a goal in us but we made a lot of changes to try and force the issue and thankfully we had enough bodies in the box on both goals to get our reward.
"A challenge was hanging over us today, there would have been loads of people taking pleasure out the fact that we were going out the cup and I have great pleasure in seeing my team into the next round and finding a way to win.
"It gives me great confidence, I know that we can improve technically and be slicker, I know we can get fitter and I know there will be mor energy in the legs after a few days rest so there are aspects that I know will improve but there are certain games where you need grit and determination and today was an example of that.
"The positive news is that Bryson got an hour under his belt, we have Ferguson back next week as well.
"It was tough for everyone associated with the club today, the fans got put through the mill, I love our fans at Dens Park, they turn up in numbers. They would have come here with high expectations today and it wasn't playing out that way.
"The players have had to dig deep to win the game, McKenna, Leigh, Logan and Considine all had nothing left, Ojo had nothing left but was still putting everything in and Sam has done for us what he has over the last wee while coming up with the winning goal.
"It was a frustrating day for him and it looked like it wasn't going to be his day, the booking was harsh on him, and I think that maybe affected him. It was a frustrating afternoon for us all but we got the right outcome.
"We came off the back of the game from Rijeka last week when we didn't get back until four in the morning, I made a few changes to try and bring a bit of freshness but in doing so a think a couple of the boys looked a bit rusty. We played the game and we were worthy of a point at St Mirren, nobody will tell me any differently, we weren't good enough to get all three but I thought we deserved something.
"Our focus has been on the European games and we took a sore one on Thursday, I managed a game for 70 minutes where I have never been in those circumstances. It was so unusual for everyone, we were geared up for reversing the score and all of a sudden after 20 minutes I am thinking of Dundee and trying to keep players fit and we went out with a whimper.
"Trying to pick the players up on Friday and Saturday was tough, but we knew if we could get through this one as we have done we would be better going forward.
"I think there has to be an understanding of the physical element for a team like ours when we play a team who are seeded better than us in Europe, we have beaten the teams we should have in Europe and we wanted to do better. Rijeka showed they were a good side and for us to be running about with 10 men for so long, I think that has had an impact.
"Hopefully we can get rest, a proper training week now and prepare properly for Kilmarnock."