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."
Sorry, we were unable to load match stats, please try again.