Ten-man Hearts progressed to the Scottish Cup semi-finals but were given a real fright by Partick Thistle.
Edgaras Jankauskas headed Hearts into a sixth-minute lead when he guided a Paul Hartley cross home with a deft touch.
Scott Boyd, Stephen McConalogue and Billy Gibson all went close for Thistle before Deividas Cesnauskis extended Hearts’ lead with a wonderful strike.
But Hearts substitute Roman Bednar was sent off and Mark Roberts ensured a thrilling close with a great finish.
The Second Division side were more than a match for their big-spending SPL opponents and recovered from a shaky start to push Hearts all the way.
The home side forced Thistle into some desperate defending inside their own penalty area in the opening minute. And the early pressure paid off, with the visitors soon falling behind to the simplest of goals.
Hartley’s in-swinging cross from the left dipped to the head of striker Jankauskas, who flicked the ball past Jags keeper Kenny Arthur from 10 yards out.
Dick Campbell’s side responded well to the setback and were enjoying some success with high balls into the Hearts penalty area, without troubling goalkeeper Craig Gordon.
Jankauskas saw another header flash just wide when he connected with a Cesnauskis delivery from the right flank.
But Thistle hit back with a Boyd looping header drifting narrowly wide and McConalogue shooting over the top from close range.
Thistle came close to an equaliser on 57 minutes. A free-kick from Gibson took a huge deflection off the defensive wall but Gordon was able to adjust his feet and was at full stretch to push the ball away.
Hearts were far from their best but Cesnauskis produced a goal of the highest quality to seemingly put the tie beyond Thistle after 63 minutes.
The Lithuanian winger gathered the ball near the right edge of the penalty area and flashed an unstoppable shot into the far corner.
Hearts introduced Bednar on the hour but the Czech striker lasted just 10 minutes.
He picked up two yellow cards, the second for a theatrical dive in the penalty area, and the home side were down to ten men.
Thistle were given a lift and Roberts twisted and turned past several challenges before finding the bottom corner of the net with a perfectly placed shot.
Roberts then set up team-mate Darren Brady with a terrific dummy but the substitute blazed his shot over the top from ten yards.
Hearts would go on to beat Hibs 4-0 in their semi-final before winning the Scottish Cup, defeating Gretna in a penalty shoot-out.
Hearts: Gordon, Neilson, Pressley, Webster, Fyssas, Cesnauskis, Brellier, Hartley, Skacel, Jankauskas, Elliot.