Scott Vernon's injury-time goal gave Aberdeen a dramatic Scottish League Cup victory against Dunfermline.
The Pars dominated the first half and almost took the lead when Andrew Barrowman's shot struck the post.
Winger Joe Cardle came close with two efforts at the Aberdeen goal in the second half.
The Dons had rarely threatened but substitute Vernon 's tap-in from Niall McGinn's cross secured victory for Craig Brown's side.
Aberdeen join Celtic, Dundee United, Hearts, Inverness, Rangers, St Johnstone and St Mirren in the fourth-round draw.
First Division Dunfermline countered from an early Dons corner and goalkeeper Jamie Langfield had to be alert to block Stephen Husband's shot.
The Pars were the more positive team and Cardle's cross was almost headed into his own net by Aberdeen's Mark Reynolds, with the defender relieved to see the ball hit the side netting.
A snapshot by Ryan Wallace flashed across the face of Langfield's goal and, moments later, the goalkeeper clutched the ball before the forward could get his toe to a through pass.
Referee John Beaton adjudged Gavin Rae's foul on Cardle to have taken place outside the area, much to Dunfermline's dismay.
Aberdeen had their first chance when McGinn latched on to Cammy Smith's pass but the winger lacked the composure needed to convert and fired over as Gallacher committed himself.
Barrowman's shot on the turn struck the goal frame and the half-time whistle soon gave the Dons respite.
Cardle drove at Aberdeen's defence early in the second half and fired narrowly wide as the Scottish Premier League visitors continued to live a charmed life.
And Cardle threatened again with Langfield touching the winger's shot onto the bar before smothering the ball.
Vernon replaced Jonny Hayes and the substitute missed the target with two efforts in the final 13 minutes of regulation time.
But Vernon did convert from close range to prevent extra-time and secure Aberdeen's place in the quarter-finals.
Dunfermline manager Jim Jefferies: "We're down and we're disappointed.
"That was a magnificent performance. Sometimes in football you need a wee rub of the ground and we didn't get it.
"We had shots on target that came back off the post. Langfield made three great saves, our goalkeeper hardly had a save to make.
"Playing like that, we'll be up there contesting what we're trying to do; put a challenge in for promotion."
Aberdeen manager Craig Brown: "We did live dangerously. If I were Jim Jefferies, I'd be very disappointed. His team did enough to at least get into extra-time.
"We fought very, very bravely and, with the second half performance, I think we just deserved it.
"If anyone deserved a goal it's Scott Vernon because he's worked really tirelessly since the start of the season without any luck at all.
"The big transformation in our team was when Russell Anderson came on. He's a brilliant captain. I didn't think there was any chance of us losing when he was in the team."
Sorry, we were unable to load match stats, please try again.
Live Text Commentary
Full Time The referee blows for the end of the match.90:00 +2:21
Assist by Niall McGinn.90:00 +2:21 Goal scored
Goal! - Scott Vernon - Dunf'mline 0 - 1 Aberdeen A goal is scored by Scott Vernon from close range high into the middle of the goal. Dunfermline 0-1 Aberdeen.90:00 +0:05
Stephen Hughes is ruled offside. Free kick taken by Paul Gallacher.88:13 Booking
Booking Stephen Hughes goes into the book.88:06
Joe Cardle takes the inswinging corner, Jamie Langfield makes a save.86:49 Substitution
Substitution Andy Kirk joins the action as a substitute, replacing Andrew Geggan.84:48
Handball decision goes against Scott Vernon. Paul Gallacher restarts play with the free kick.84:22
Corner taken by Chris Clark from the right by-line, clearance made by Andrew Geggan.83:45
The referee blows for offside against Andrew Barrowman. Indirect free kick taken by Stephen Hughes.81:59
Close range effort by Scott Vernon misses to the right of the goal.80:45
Scott Vernon fouled by Stephen Husband, the ref awards a free kick. Mark Reynolds takes the free kick.79:09
Centre by Stephen Hughes.79:09 Substitution
Substitution Josh Falkingham goes off and Ryan Thomson comes on.79:09
Foul by Stephen Husband on Chris Clark, free kick awarded.78:10
Shot by Ryan Wallace from outside the box goes high over the crossbar.77:12
Effort on goal by Scott Vernon from just inside the penalty area goes harmlessly over the target.74:46 Substitution
Substitution Clark Robertson goes off and Stephen Hughes comes on.73:41
Gavin Rae takes a shot. Andy Dowie gets a block in. Outswinging corner taken from the right by-line by Isaac Osbourne, Effort from inside the area by Russell Anderson misses to the right of the target.72:55
Corner taken right-footed by Isaac Osbourne from the right by-line to the near post, Andrew Geggan makes a clearance.
Joe Cardle takes the outswinging corner, Callum Morris takes a shot. Blocked by Isaac Osbourne.69:30
Ryan Wallace takes a shot.66:42 Substitution
Substitution Russell Anderson joins the action as a substitute, replacing Josh Magennis.65:55
Indirect free kick taken by Paul Gallacher.65:55 Booking
Booking The referee shows Clark Robertson a yellow card.65:12
Cameron Smith takes a shot. Blocked by Callum Morris. Inswinging corner taken right-footed by Niall McGinn played to the near post, Ryan Wallace makes a clearance. Clark Robertson challenges Ryan Wallace unfairly and gives away a free kick.64:45
Free kick awarded for a foul by Callum Morris on Cameron Smith. Isaac Osbourne restarts play with the free kick.64:09
Joe Cardle takes a shot.62:43
Ryan Wallace is flagged offside by the assistant referee. Indirect free kick taken by Mark Reynolds.60:08 Substitution
Substitution Johnny Hayes leaves the field to be replaced by Scott Vernon.58:36
Johnny Hayes decides to take a short corner.56:30
Andrew Barrowman concedes a free kick for a foul on Chris Clark. Indirect free kick taken by Jamie Langfield.53:19
Isaac Osbourne concedes a free kick for a foul on Jordan McMillan. Joe Cardle restarts play with the free kick.51:18
Joe Cardle has shot on goal from just outside the area which goes wide of the right-hand upright.50:40
Johnny Hayes takes a shot. Paul Gallacher makes a save.49:57
Andrew Geggan gives away a free kick for an unfair challenge on Gavin Rae. Direct free kick taken by Isaac Osbourne.48:43
Andrew Barrowman challenges Isaac Osbourne unfairly and gives away a free kick. Josh Magennis restarts play with the free kick.45:01
The referee gets the second half started.45:00 +1:08 Half time
Half Time The match has reached half-time.43:38
Cameron Smith takes a shot. Paul Gallacher makes a comfortable save.42:57
Foul by Josh Falkingham on Clark Robertson, free kick awarded. Free kick taken by Jamie Langfield.42:04
Effort from deep inside the area by Andrew Barrowman bounces off the post. Inswinging corner taken right-footed by Joe Cardle from the right by-line, Mark Reynolds makes a clearance.41:31
Inswinging corner taken right-footed by Joe Cardle from the left by-line, clearance by Josh Magennis.40:46
Effort on goal by Niall McGinn from inside the area goes harmlessly over the bar.39:17
Free kick awarded for a foul by Joe Cardle on Josh Magennis. Johnny Hayes delivers the ball from the free kick left-footed from left channel, clearance made by Andrew Geggan.37:58
Cameron Smith gives away a free kick for an unfair challenge on Stephen Jordan. Joe Cardle crosses the ball from the free kick left-footed from left channel, save made by Jamie Langfield.36:51
Ryan Wallace produces a shot on goal direct from the free kick.36:51 Booking
Booking Gavin Rae goes into the referee's book.36:22
Andrew Considine concedes a free kick for a foul on Andrew Barrowman.30:55
Foul by Andrew Barrowman on Mark Reynolds, free kick awarded. Jamie Langfield takes the direct free kick.28:36
Stephen Husband gives away a free kick for an unfair challenge on Mark Reynolds. Jamie Langfield restarts play with the free kick.27:55
Andrew Considine fouled by Ryan Wallace, the ref awards a free kick. Clark Robertson restarts play with the free kick.27:16
Niall McGinn is ruled offside. Paul Gallacher restarts play with the free kick.23:37
Gavin Rae is ruled offside. Free kick taken by Paul Gallacher.22:02
Ryan Wallace produces a right-footed shot from deep inside the penalty box which goes wide of the left-hand upright.16:39
Outswinging corner taken from the left by-line by Johnny Hayes, clearance by Andy Dowie.14:52
The assistant referee signals for offside against Ryan Wallace. Indirect free kick taken by Jamie Langfield.12:53
The offside flag is raised against Joe Cardle. Free kick taken by Jamie Langfield.11:55
The offside flag is raised against Joe Cardle. Jamie Langfield restarts play with the free kick.11:25
Inswinging corner taken by Joe Cardle from the left by-line, clearance made by Andrew Considine.9:12
Free kick awarded for an unfair challenge on Johnny Hayes by Stephen Husband. Free kick taken by Clark Robertson.5:54
The referee penalises Andrew Barrowman for handball. Jamie Langfield takes the indirect free kick.4:34
Stephen Husband takes a shot. Save made by Jamie Langfield.0:00
The referee gets the game started.
Live data and text provided by our data suppliers