Hearts reached the Betfred Cup quarter-finals thanks to Olly Lee's late winning goal at Dunfermline.
The Englishman struck on 79 minutes to take the Edinburgh club into the last eight past their resilient Fife opponents.
Dunfermline had been the better team in the first half but Hearts increased the pace after the interval and were eventually rewarded through Lee's low finish. Goalkeeper Zdenek Zlamal pulled off two excellent saves to deny Faissal El Bakhtaoui and substitute Aidan Connolly during the second half, which helped his club into the next round.
Dunfermline, of course, eliminated Hearts from the competition last year in the final group game. That cost head coach Ian Cathro his job and added some extra intrigue to this tie. The visitors relegated Kyle Lafferty to the substitutes' bench despite his winning goal against Celtic in the league last weekend.
It was Dunfermline who enjoyed the stronger start and they hit the post through striker Faissal El Bakhtaoui on 11 minutes. Allan Johnston's side showed plenty competitive edge and Hearts found themselves defending several cross balls into their penalty box.
Attempts to build attacking moves of their own were hindered by cheap losses of possession on a slippery playing surface. Uche Ikpeazu and Lee both had attempts at Lee Robinson's goal, but the Dunfermline goalkeeper was only tested by the former during the first 45 minutes.
Hearts introduced the Australian international midfielder Oliver Bozanic during the break. He took Aaron Hughes' place, with Peter Haring moving from midfield to centre-back. El Bakhtaoui's pace had caused problems on occasions in the first half and he continued to be the main attacking outlet for the home team.
On 69 minutes, after Ryan Williamson's driving run and corss from the right, El Bakhtaoui took to the air for an acrobatic volley at goal. The Hearts keeper Zlamal was equal to the task with an impressive save high to his right to prevent a certain opening goal.
Lafferty came on for Ikpeazu to help the Edinburgh side press in search of a breakthrough. Jake Mulraney forced his way past Jackson Longridge and Daniel Devine but pulled his shot wide from 16 yards. He was then substituted for Callumn Morrison.
Lee's composure on the ball earned Hearts the lead 11 minutes from the end. Receiving a pass from Steven MacLean, the midfielder controlled the ball and rolled an accurate low shot across Robinson and into the bottom corner.
That brought some smoke bombs from the away end, causing a delay in play. Dunfermline now had to chase the game with little time left. Danny Devine's looping header was brilliantly saved by Zlamal in the closing stages. Then the Czech used his legs to somehow thwart substitute Connolly, who looked certain to score, in stoppage-time.
Those in maroon were relieved to hear the final whistle having been made to work hard for their place in the next round by their Championship hosts. Lafferty went to the away support to hand them his shirt and shinpads before strolling off down the tunnel.
Dunfermline (3-4-1-2): Robinson; Ashcroft, Durnan, Devine; Williamson, Craigen (Ryan 86), Vincent, J Longridge; L Longridge; El Bakhtaoui, Hippolyte (Connolly 81). Unused subs: Gill, Morrison, Higginbotham, Thomson, Smith.
Hearts (4-4-2): Zlamal; M Smith, Souttar, Hughes (Bozanic 46), Garuccio; Mulraney (Morrison 79), Haring, Lee, Naismith; Ikpeazu (Lafferty 70), MacLean. Unused subs: Doyle, Cochrane, McDonald, Burns.
Referee: Bobby Madden.