Hearts beat Queen of the South in a penalty shoot-out to reach the Scottish League Cup quarter-finals.
The hosts led three times through Kevin McHattie's strike, Jamie Hamill's spot-kick and Danny Wilson's extra-time effort.
Queens levelled on each occasion through Ryan McGuffie, Michael Paton and Chris Higgins.
But Dale Carrick struck the winning penalty after Jamie MacDonald had saved Michael Paton's attempt.
The Doonhamers started the match the better of the two teams and forced a couple of free-kicks on the edge of the Hearts box but failed to test Jamie MacDonald.
But with almost their first attack the home side went into the lead.
Queens' defence failed to clear from the edge of their area and McHattie took full advantage, driving the ball low and hard into the bottom corner of the net.
The visitors responded well and forced a corner from which McGuffie forced home after MacDonald had made a terrific save from the defender's initial header.
That was no less than Queens deserved with the Scottish Championship side more than a match for their Premiership opponents.
And Jim McIntrye's side should have gone in front before the break.
Hamill slid in to clear from the edge of the Hearts penalty box but the ball ended up at the feet of Derek Lyle, who looked certain to score only to blast high over the crossbar.
Two minutes before half-time Paton was inches away from finding the net after a great run and cross by Iain Russell.
The second half started with a bang when referee John McKendrick awarded the home side a penalty.
Jamie Walker tried to thread the ball through two Queens defenders and tumbled to the ground and visiting management team Jim McIntyre and Gerry McCabe were furious when McKendrick pointed to the spot.
Hamill fired high into the roof of the net from 12 yards.
Frustration began to creep into Queens' play and Russell found himself in the referee's book after going down too easily following a challenge by Dylan McGowan.
However, the Dumfries side kept pushing forward and deservedly equalised for the second time on the hour mark.
Lyle's pace took him away from McGowan and his cross was met perfectly by Paton, who made no mistake from four yards out.
Hearts took the lead for the third time three minutes into extra time. A corner from the right was met by Hamill on the edge of the box and his shot was flicked into the corner of the goal by Wilson for his first of the season.
But Higgins' strike forced a penalty shoot-out and though Hamill fired over, a miss by Higgins and Paton's saved effort allowed Carrick to seal victory.
Hearts manager Gary Locke: "It's probably the first time this season we've not defended very well.
"We're going to get that with young players but they're learning all the time. The main thing is we're in the hat for the next round.
"They're fantastic young lads to work with and they're giving us everything."
Queen of the South manager Jim McIntyre: "Without a shadow of a doubt, I thought we were excellent.
"I didn't think it was a penalty at all and for their third goal I didn't think it was a corner kick. They are big moments in the game.
"The players were magnificent, going behind three times and coming back three times. It goes to the lottery of the penalty shoot-out and we just can't get over the line."
- 01 MacDonald
- 03 McHattie
- 04 Wilson
- 05 McGowan Booked
- 16 McKay (McGhee - 68' )
- 02 Hamill
- 08 Robinson (Carrick - 91' )
- 15 Holt
- 12 Paterson
- 14 Walker
- 29 Oliver (B King - 68' )
- 13 Ridgers
- 30 McGhee
- 19 B King
- 20 Tapping
- 18 Carrick
Queen of South
- 01 Antell
- 02 McGuffie (Mitchell - 87' )
- 03 Holt
- 04 Dzierzawski
- 05 Dowie
- 06 Higgins
- 07 McShane
- 08 Young (Reilly - 97' )
- 10 Paton
- 11 Russell Booked (Mitchell - 79' )
- 09 Lyle
- 12 Atkinson
- 17 Durnan
- 15 Carmichael
- 16 Mitchell
- 14 Reilly
Live Text Commentary
Derek Lyle scores a penalty. Hearts 1-1 Queen of South on penalties.120:44
Penalty missed by Christopher Mitchell.120:34 Penalty
Kevin Dzierzawski scores a penalty. Hearts 4-1 Queen of South on penalties.120:21
Spot kick missed by Jamie Hamill.120:09 Penalty
Dylan McGowan scores a penalty. Hearts 2-0 Queen of South on penalties.120:07 Penalty
Billy King scores a penalty. Hearts 3-0 Queen of South on penalties.120:05 Penalty
Penalty scored by Jordan McGhee. Hearts 1-0 Queen of South on penalties.120:01
The first player steps forward to start the penalty shoot-out.120:01 Penalty
Dale Carrick scores a penalty. Hearts 1-0 Queen of South on penalties.120:00 +2:03
The match is going to penalties.119:38
Michael Paton has an effort at goal and missed to the right of the net.119:02
Shot from the free kick by Kevin McHattie went wide of the right-hand post.118:50
Kevin McHattie takes the free kick.118:30
Jamie Walker fouled by Andrew Dowie, the ref awards a free kick.117:23
Clearance by Callum Paterson.117:15
Corner taken by Christopher Mitchell from the right by-line.116:00 Goal scored
Goal! - Christopher Higgins - Hearts 3 - 3 Queen of S Christopher Higgins scores with a right foot finish. Hearts 3-3 Queen of South.115:24
Christopher Mitchell crosses the ball in from the free kick.114:23
Jason Holt concedes a free kick for a foul on Michael Paton.111:28
Shot by Ian McShane went over the bar.
Danny Wilson manages to make a clearance.109:03
Corner from the taken by Christopher Mitchell.108:40
Corner taken by Christopher Mitchell from the right by-line.107:52
Headed chance falls to Daniel Carmichael.107:43
Centre by Christopher Mitchell.105:01
The second half of extra-time kicks-off.104:38
Jason Holt takes a shot.102:57
Andrew Dowie takes the free kick.102:48
Christopher Mitchell fouled by Jason Holt, the ref awards a free kick.101:28
The ball is delivered by Billy King.100:06
Clearance by Derek Lyle.99:59
Corner from the right by-line taken by Jamie Walker.98:37
Jamie Hamill takes a shot and went wide left of the net.98:01
Jamie MacDonald restarts play with the free kick.97:40
Michael Paton concedes a free kick for a foul on Jason Holt.97:13
Shot by Callum Paterson missed to the left of goal.96:47 Substitution
Substitution Gavin Reilly comes on in place of Derek Young.96:30
Header at goal by Derek Lyle to the left of the net.96:21
Daniel Carmichael produces a cross.95:52
Clearance by Jamie Hamill.95:47
The ball is sent over by Christopher Mitchell.93:45
Christopher Mitchell delivers the ball.92:30
Assist on the goal came from Jamie Hamill.92:30 Goal scored
Goal! - Danny Wilson - Hearts 3 - 2 Queen of S Danny Wilson scores with their left foot. Hearts 3-2 Queen of South.91:28
Corner taken by Jamie Walker.90:01 Substitution
Substitution Scott Robinson leaves the field to be replaced by Dale Carrick.90:00 +3:38
The whistle goes for the end of normal time.90:00 +1:45
Free kick crossed by Christopher Mitchell.90:00 +1:23
Free kick awarded for a foul by Kevin McHattie on Christopher Mitchell.90:00 +0:01
Daniel Carmichael has an effort at goal and missed to the right of the net.89:16
Free kick taken by Jamie MacDonald.89:09
Unfair challenge on Kevin McHattie by Michael Paton results in a free kick.86:45 Substitution
Substitution Christopher Mitchell comes on in place of Ryan McGuffie.85:19
Shot by Ian McShane. Jamie MacDonald catches the ball.85:06
Dylan McGowan heads at goal.84:57
Andrew Dowie makes a clearance.84:45
The ball is sent over by Jamie Hamill.82:29
Centre by Kevin Holt.80:52
Dylan McGowan makes a clearance.80:37
Corner from the right by-line taken by Ian McShane.78:25 Substitution
Substitution Iain Russell leaves the field to be replaced by Daniel Carmichael.77:49
Jamie Walker has an effort at goal and missed to the left of the net.76:47
Free kick taken by Calum Antell.76:40
Free kick awarded for an unfair challenge on Andrew Dowie by Callum Paterson.74:39
Jamie MacDonald takes the free kick.72:55
Jason Holt takes a weak shot and went wide of the left-hand post.72:09
Kevin Holt crosses the ball.69:48
Ian McShane takes a shot. Jamie MacDonald safely holds on.69:24
Free kick crossed by Ian McShane.69:14
Jordan McGhee concedes a free kick for a foul on Iain Russell.68:35
Jordan McGhee crosses the ball.67:40
Derek Lyle takes a shot and cleared the crossbar.67:23 Substitution
Substitution Billy King is brought on as a substitute for Gary Oliver.67:03 Substitution
Substitution (Hearts) makes a substitution, with Jordan McGhee coming on for Brad McKay.64:58
Andrew Dowie manages to make a clearance.64:49
Corner from the right by-line taken by Kevin McHattie.64:05
Ian McShane crosses the ball in from the free kick.63:57 Booking
Dylan McGowan is cautioned.63:50
Unfair challenge on Iain Russell by Dylan McGowan results in a free kick.62:47
Free kick taken by Jamie MacDonald.62:25
Michael Paton takes the chance to get an effort at goal and missed to the right of the target.62:00
Calum Antell restarts play with the free kick.61:48
Free kick awarded for an unfair challenge on Derek Young by Jason Holt.61:09
Assist by Derek Lyle.61:09 Goal scored
Goal! - Michael Paton - Hearts 2 - 2 Queen of S Michael Paton slots the ball right footed into the goal. Hearts 2-2 Queen of South.59:11
Free kick crossed by Ian McShane.59:00
Free kick awarded for an unfair challenge on Iain Russell by Jamie Hamill.57:32
Free kick taken by Jamie MacDonald.57:24
Iain Russell is flagged offside by the assistant referee.56:42
Jamie MacDonald restarts play with the free kick.56:33 Booking
Iain Russell goes into the referee's book for unsporting behaviour.56:20
Iain Russell challenges Dylan McGowan unfairly and gives away a free kick.54:49
Shot by Jason Holt missed to the right of the target.52:51
Callum Paterson makes a clearance.52:45
The ball is crossed by Ryan McGuffie.50:42 Goal scored
Goal! - Jamie Hamill - Hearts 2 - 1 Queen of S Penalty taken right-footed by Jamie Hamill and scored. Hearts 2-1 Queen of South.50:09
Christopher Higgins challenges Jamie Walker unfairly and gives away a Penalty.49:17
Jamie MacDonald restarts play with the free kick.49:05
Free kick awarded for an unfair challenge on Callum Paterson by Iain Russell.47:53
Jamie Hamill restarts play with the free kick.47:41
Unfair challenge on Scott Robinson by Ryan McGuffie results in a free kick.47:13
Danny Wilson restarts play with the free kick.47:04
Ian McShane concedes a free kick for a foul on Jamie Hamill.45:01
The match restarts for the second half.45:00 +0:38 Half time
Half Time The half-time whistle blows.45:00 +0:13
Strike comes in from Kevin McHattie from the free kick.44:36
Free kick awarded for an unfair challenge on Jamie Hamill by Christopher Higgins.43:44
Shot by Michael Paton went wide left of the target.40:21
Iain Russell takes a shot and went wide left of the target.37:59
Jamie MacDonald takes the free kick.37:54
The offside flag is raised against Derek Lyle.34:36
Calum Antell restarts play with the free kick.34:26
Unfair challenge on Iain Russell by Callum Paterson results in a free kick.33:23
Derek Lyle takes a shot and cleared the bar.32:32
Calum Antell takes the free kick.32:24
Callum Paterson gives away a free kick for an unfair challenge on Iain Russell.30:58
Danny Wilson manages to make a clearance.30:52
The ball is delivered by Ryan McGuffie.26:38
Calum Antell takes the free kick.26:35
The referee blows for offside against Jamie Walker.23:29
Free kick taken by Andrew Dowie.23:23
Foul by Kevin McHattie on Michael Paton, free kick awarded.22:28
Calum Antell restarts play with the free kick.22:18
Free kick awarded for an unfair challenge on Andrew Dowie by Kevin McHattie.22:09
Free kick taken by Scott Robinson.21:50
Free kick awarded for an unfair challenge on Gary Oliver by Andrew Dowie.21:17
Dylan McGowan takes the chance to get an effort at goal and missed to the right of the net.20:56
Corner from the left by-line taken by Jamie Walker.19:46
Free kick crossed by Kevin McHattie.19:38
Iain Russell gives away a free kick for an unfair challenge on Jason Holt.19:10 Goal scored
Goal! - Ryan McGuffie - Hearts 1 - 1 Queen of S Ryan McGuffie scores a left footed goal. Hearts 1-1 Queen of South.18:54
Ryan McGuffie heads at goal. Parried by Jamie MacDonald back into danger.18:17
Corner taken by Ian McShane from the right by-line.17:56
Clearance made by Kevin McHattie.17:33
Ian McShane crosses the ball in from the free kick.17:26
Free kick awarded for an unfair challenge on Ryan McGuffie by Jamie Walker.16:32
Callum Paterson gives away a free kick for an unfair challenge on Kevin Holt.15:10
The ball is crossed by Iain Russell.13:59
The assist for the goal came from Jason Holt.13:59 Goal scored
Goal! - Kevin McHattie - Hearts 1 - 0 Queen of S Kevin McHattie scores with their left foot. Hearts 1-0 Queen of South.12:53
Header at goal by Christopher Higgins goes over the bar.12:33
Ian McShane takes the free kick.12:24
Foul by Callum Paterson on Derek Young, free kick awarded.12:07
Free kick taken by Calum Antell.12:03
Foul by Callum Paterson on Kevin Holt, free kick awarded.9:50
Shot by Callum Paterson. Calum Antell catches the ball.9:35
Danny Wilson takes the free kick.9:22
Michael Paton gives away a free kick for an unfair challenge on Kevin McHattie.9:09
Jamie MacDonald restarts play with the free kick.8:48
Corner taken by Ian McShane from the left by-line.8:17
Iain Russell has an effort at goal.7:26
Scott Robinson takes the free kick.7:18
Derek Young concedes a free kick for a foul on Scott Robinson.6:13
Jamie MacDonald takes the free kick.6:06
Jamie Hamill fouled by Derek Lyle, the ref awards a free kick.5:46
Free kick crossed by Ian McShane.5:34
Foul by Dylan McGowan on Derek Young, free kick awarded.5:18
Derek Young takes the free kick.5:03
Free kick awarded for an unfair challenge on Ian McShane by Callum Paterson.1:39
Clearance by Andrew Dowie.1:34
The ball is sent over by Jamie Hamill.0:00
The game kicks-off.
Live data and text provided by our data suppliers