Queen of the South were denied a second top-flight scalp as Hearts squeezed into the fourth round of the Scottish League Cup victory on penalties at Tynecastle.
The visitors, who knocked out holders St Mirren in the previous round, hit back from a goal down three times to force a tense shoot-out as it finished 3-3 after 120 extra-time.
But Chris Mitchell and Michael Paton both missed from the spot as Hearts recovered from Jamie Hamill's miss to run out 4-2 winners.
A thrilling contest got off to a lively start as Callum Paterson's low shot forced an early save from Calum Antell before Chris Higgins looped a header over the bar at the other end.
Hearts soon grabbed an opener on 13 minutes when Kevin McHattie raced down the left and cut inside to fire a low drive across Antell and into the far corner to notch his first goal of the season in some style.
But the lead lasted just six minutes as Ian McShane's outswinging corner picked out Ryan McGuffie, whose header was parried by Jamie McDonald only for McGuffie to slam in the loose ball.
Queen of the South missed a golden chance to snatch the lead when slack home defending gifted the ball to Derek Lyle, who lashed over the bar from six yards with only MacDonald to beat.
Iain Russell sliced wide and Paton's effort grazed the upright as the visitors finished the half on top, but it was Hearts who reclaimed the lead from the penalty spot six minutes after the break.
Jamie Walker was hauled down by Higgins as he tried to latch onto Hamill's through-ball, and Hamill stepped up to beat Antell from the spot.
But again the visitors responded on the hour mark as a flowing counter-attack was capped by a composed close-range finish from Paton.
Paton and Lyle both went close for the confident visitors, while Jason Holt dragged a half-volley wide as Hearts tried to regain a foothold in the tie.
McShane fired straight as McDonald as the game drifted into extra-time, which was just three minutes old when Danny Wilson stuck out a boot to divert Hamill's low-driven cross past Antell.
Queen's again refused to lie down and they conjured up another equaliser in the 117th minute when Hamill's rushed clearance fell kindly for Higgins, who hammered his shot beyond MacDonald and into the top corner.
McHattie's 25-yard free-kick was inches away from preventing a penalty shoot-out, which started badly for Hearts as Hamill hit his side's second spot-kick over the bar.
But Chris Mitchell's effort cannoned back off the crossbar, and MacDonald saved from Paton while Billy King and Dylan McGowan were on target for the hosts.
Kevin Dzierzawski made it 3-2, but Dale Carrick held his nerve to beat Antell from 12 yards and send Hearts into the quarter-finals.