Scott Wilson's last-minute header sent Dunfermline into the quarter-finals of the Scottish Cup at Hearts' expense.
Captain Scott Wilson led the Pars into the quarter-finals
It looked like the holders would take the Pars back to Tynecastle for a replay until Wilson headed the ball home from Adam Hammill's cross.
Home defender Phil McGuire had headed off the line, while goalkeeper Dorus De Vries saved well from Saulius Mikoliunas and Michal Pospisil.
The Pars failed to create a clear-cut chance until that dramatic winner.
Scotland goalkeeper Craig Gordon had been controversially left on the bench by Hearts head coach Valdas Ivanauskas.
New signing Laryea Kingston made his debut in the Hearts midfield.
Defender Christophe Berra dropped out with an ankle injury and was replaced with Ibrahim Tall as Ivanauskas made six team changes.
Dunfermline had to do without captain Greg Shields through injury and on-loan Hibernian midfielder Stephen Glass, who was cup-tied.
Hearts were the more dangerous from the start and forced three quick corners.
There were claims for a penalty when Mikoliunas was challenged by Wilson, who accused the Lithuanian of diving.
McGuire failed to get a decent touch when found inside the Hearts box by Hammill.
And Neil McCann's timely interception denied former Hearts midfielder Stephen Simmons a shooting chance.
Laryea Kingston made his debut for Hearts
But it was a woeful first half with few chances made by either team.
Dunfermline were the first to threaten in the second half after goalkeeper Steve Banks fumbled a cross.
Hammill's chip to the back post found Stevie Crawford, but the striker's header struck the back of Lee Wallace.
Goalkeeper Dorus De Vries did well to smother a shot on the turn from Michal Pospisil at the other end.
McGuire headed clear to prevent a powerful Driver effort entering the net.
And De Vries then palmed away a Mikoliunas drive before clawing a Pospisil header from eight yards off the line.
Dunfermline weathered the storm and Hammill got beyond the Hearts defence, but his low cross across the face of goal just evaded Crawford.
Hammill screwed an effort well wide when set up neatly by substitute Jim McIntyre, while Hearts replacement Edgar Jankauskas fired into the side netting.
A Roman Bednar chip from a difficult angle landed on the roof of the crossbar after a McGuire slip had left De Vries stranded.
But it was Dunfermline who prevailed at the end of an exciting second period with Wilson's last-minute winner.
Dunfermline: De Vries, Ross, McGuire, Wilson, Scott Morrison, O'Brien (Owen Morrison 86), Mason, Simmons, Hammill, Crawford (McIntyre 79), Burchill (Hamilton 68).
Subs Not Used: McKenzie, Bamba.
Goal: Wilson 90.
Hearts: Banks, Zaliukas, Karipidis (John Armstrong 61), Tall, Wallace, Mikoliunas (Jankauskas 75), Kingston, McCann, Driver, Pospisil (Bednar 67), Elliot.
Subs Not Used: Gordon, Brellier.
Booked: Driver, Karipidis.
Ref: M McCurry