An extra-time Callum Paterson strike saw Hearts dispose of League One Forfar Athletic to reach the third round of the Scottish League Cup.
Kevin McHattie gave Hearts the lead after 74 minutes only for Michael Dunlop to equalise with a header.
Forfar finished the match with only nine men; Danny Denholm and Kevin Nicoll were dismissed.
The visitors were dominant, but kept at bay by the brilliance of veteran keeper Rab Douglas in the home goal.
The 43-year-old pulled off a string of magnificent stops including a Gavin Reilly penalty after 69 minutes when Nicoll handled in the box.
Reilly struck the ball well but Douglas dived low to his left to push it away.
There was little he could do though five minutes later when McHattie gave Hearts the lead.
The Forfar defence failed to clear their penalty area and McHattie pounced to fire home the opener.
Douglas was called into action again when he magnificently cleared a Juanma header that looked destined for the bottom corner.
With seven minutes left for play, Forfar struck with one of their few chances.
A long ball into the Hearts box was missed by the defence, and Aberdeen youngster Michael Dunlop sent a looping header over Hamilton and sent the home crowd wild.
As the 90 minutes edged closer the home side were reduced to 10 men when Denholm picked up his second yellow card of the evening and headed for an early bath.
Chances were few and far between in extra time, but Hearts took the lead on the stroke of half-time.
Callum Morrison, 16, sent a corner deep into the box where Paterson was waiting to fire home through a cluster of bodies.
Forfar were reduced to nine men in the final minute when Nicoll was shown a straight red for a foul on Morrison and the home side's challenge was over with Hearts progressing to the third round draw on Thursday.