Substitute Alex Lowry struck two minutes into injury time to send Hearts into the Viaplay Cup semi-finals with a 2-1 win away to Kilmarnock.
Steven Naismith’s team had forged in front through Jorge Grant’s first-half strike only to be pegged back by Brad Lyons’ equaliser.
With extra time looming, Lowry – who had been on the pitch for less than two minutes – took a pass from Liam Boyce before rolling his shot into the far corner of the net.
It was the on-loan Rangers forward’s first goal for Hearts since arriving at Tynecastle on loan last month and will ease some of the pressure that had been mounting on Naismith.
Kilmarnock had made just one change from the side that drew with Dundee at the weekend with David Watson coming in for Marley Watkins, the match winner against Celtic in the previous round.
There were three changes from the Hearts team beaten by St Mirren. In came Grant, Toby Sibbick and Alan Forrest, replacing Nathaniel Atkinson, Boyce and Beni Baningime.
The Tynecastle side came into the tie on a run of just one win from six games and the travelling support made their feelings knows as they unfurled a banner before kick-off that read, “funded by fans, ran by clowns, we deserve better”.
It was Hearts who had the first chance but a drive from Lawrence Shankland drifted well wide of goal.
At the other end, Matty Kennedy’s mazy run carried him into the box only for Zander Clark to make a strong save to keep out his shot.
Five minutes before half-time, Hearts were ahead. Kyle Rowles carried the ball forward before feeding Shankland. The Hearts captain laid it off for Grant whose first-time finish found the bottom corner.
Kilmarnock replied with a Kyle Magennis volley that sailed off target, with the same player then coming even closer with a good chance early in the second half.
Hearts almost doubled their lead when Stephen Kingsley’s inventive effort struck the crossbar. The impressive Magennis then teed up Kyle Vassell at the other end and the striker’s driven effort was well pushed away by Clark.
The home side, though, would not be denied after 67 minutes. Vassell found Kennedy wide on the left and the winger’s trickery fooled Sibbick to earn himself a bit of space. The former Aberdeen player then weighted the perfect cross for Lyons to head home.
The home side looked the ones most likely to win it within the regulation 90 minutes but instead it was Hearts who will be heading to Hampden after Lowry’s dramatic late intervention.
Kilmarnock’s next Scottish Premiership match is at home to St Mirren on Saturday while Hearts are away to Ross County. Both games kick off at 3pm.