Partick Thistle stormed back from a goal behind to knock Dunfermline out of the Scottish Cup thanks to two fourth-round goals from Liam Buchanan.
Buchanan scored his second with three minutes remaining
Scott Wilson headed the Pars into a deserved lead after 49 minutes after they had dominated the first half.
But Buchanan drove in a 68th-minute equaliser for Thistle.
And, after Thistle had two goals chopped off for infringements, Buchanan pounced to score three minutes from time following intense pressure.
Dunfermline had made four changes from the side beaten by St Johnstone in Division One on Saturday.
Stephen Glass returned from injury, while Calum Woods, Kevin Harper and player-manager Jim McIntyre were also back in the starting line-up.
Danny Murphy, Jamie Harris, Greg Ross and Darren Young were the men missing out.
The Thistle side was unchanged after their fine win over Division One leaders Hamilton.
But it was the visitors who dominated the first half in terms of possession and chances.
Mark Burchill mis-kicked his attempt at a volley from four yards following a fine Harper cross then fired another effort off the legs of goalkeeper Jonny Tuffey.
Glass volleyed inches wide of the far post after being set up by Burchill, while Jim Hamilton fired just over the bar.
Dunfermline were left to rue chances missed in the first half
Thistle rarely threatened, their only attempts on goal being long-range efforts from Scott Chaplain and Gary Harkins that did were well off target.
Wilson, who had passed a late fitness test to play, finally made the breakthrough when he headed into the top right-hand corner from a Glass free-kick.
Thistle almost responded immediately when a powerful Harkins free-kick from 22 yards was deflected wide for a corner.
Dunfermline midfielder Stephen Simmons misdirected a header in front of goal as the visitors looked to kill the game.
Thistle boss Ian McCall had brought on Stevie Murray and Paul Keegan and that increased the threat from the hosts.
When McIntyre and Hamilton failed to clear following a corner, Woods had to make a desperate clearance from in front of his own goal.
And, after Mark Roberts played the ball through, Buchanan fired the ball home from 15 yards.
Chaplain fired the ball into the Dunfermline net, but the assistant referee flagged for offside after Roberts and Keegan blocked the view of goalkeeper Paul Gallacher.
Rowson had the ball in the net seconds later, but his effort from 18 yards was ruled out because the referee had already blown the whistle for an infringement in the defensive wall.
Gallacher was forced into a fine save to prevent Buchanan scoring on the turn.
But, when the former Scotland goalkeeper was unconvincing with his punch, Buchanan pounced to score the winner following a Rowson mis-kick and secured a spot against Livingston in the next round.
Partick: Tuffey, Harkins (Keegan 60), Archibald, Twaddle, Robertson, Storey, Rowson, McKinlay (Murray 60), Buchanan, Roberts, Chaplain.
Subs Not Used: Kinniburgh, Hinchcliffe, McStay.
Goals: Buchanan 68, 87.
Dunfermline: Gallacher, Woods, Scott Thomson, Scott Morrison, Wilson, Harper (McManus 64), Simmons, McIntyre, Glass, Burchill, Hamilton.
Subs Not Used: Crawford, Phinn, Williamson, Murdoch.
Booked: Woods, Burchill, Wilson.
Goals: Wilson 49.
Ref: Scott McDonald