Jamie Hamill went from hero to villain with Hearts suffering more pain in their most difficult season as nine-man Inverness reached the League Cup final with a dramatic penalty shoot-out win.
Hamill scored from two free-kicks inside three minutes in response to Greg Tansey's spectacular 54th-minute strike at Easter Road, and Hearts looked destined to face Aberdeen in the final when Josh Meekings joined fellow Inverness centre-back Gary Warren in an early bath as the 90 minutes elapsed.
But Nick Ross scrambled an unlikely equaliser in the fifth minute of injury-time and Inverness comfortably held out in extra-time before triumphing in the spot-kicks battle after Hamill's miss handed them the advantage.
Ross Draper secured a 4-2 shoot-out success to send the Highland outfit into their first major final.
Caley Thistle's win turned the tables following their shoot-out defeat by 10-man Hearts at the same stage and stadium last year and it denied the administration-hit Edinburgh side a much-needed financial boost.
Relegation-doomed Hearts survived a difficult first 10 minutes and were almost behind within two when Danny Wilson lost the ball to Billy McKay deep inside his half. However, the striker's pass to Draper was slightly overhit and the stretching midfielder skied his shot.
Aaron Doran went close twice from long range but Hearts steadied and improved further midway through the half as they knocked the ball about well.
Warren and Marley Watkins were booked for thwarting Hearts breaks and Inverness goalkeeper Dean Brill beat away Sam Nicholson's powerful long-range strike, but Thistle created the chance of the half five minutes before the break.
Draper curled a ball round Brad McKay to send Billy McKay through on goal but Jamie MacDonald made a stunning save from 10 yards.
Hearts replaced David Smith with Ryan Stevenson before the second half but Inverness started as strongly as they had the first and Tansey struck a powerful shot into the top corner from more than 20 yards after the ball broke off James Vincent.
MacDonald was immediately booked for protesting as some of his team-mates gestured for handball.
Hearts soon survived some desperate moments but they almost levelled when Meekings and Graeme Shinnie collided as they tried to cut out Wilson's diagonal ball. However, Brill stopped Callum Paterson's shot and David Raven got back to clear the headed rebound off the line.
On-loan West Ham forward Paul McCallum came on for his Hearts debut just before the dramatic turnaround, sparked when Nicholson was brought down on the edge of the box. Nicholson appeared to have been pulled by Watkins but Warren also made a challenge and John Beaton showed a second yellow card to the defender.
Kevin McHattie looked to be shaping up to hit the free-kick but touched it to Hamill, who had been standing in front of the ball. The midfielder swivelled and struck a low shot that took a major deflection off the wall and nestled in the far corner.
Hamill then repeated the feat from further out after Meekings had fouled Dale Carrick. The former Kilmarnock player curled the ball into the near top corner with Brill only able to push it further in.
MacDonald saved headers from McKay and Meekings and Nicholson was stretchered off while clutching his ribs but Hearts looked safe when MacDonald saved Shinnie's 25-yard volley and Meekings was shown a straight red card for a foul on Scott Robinson.
But there was a further twist as Ross scrambled the ball home from close range with almost the last kick of regulation time after several Hearts defenders failed to clear a hopeful ball into the box.
Extra-time initially resembled a training ground exercise of defence against attack as midfielder Draper joined substitute Danny Devine at centre-back.
But the Highlanders survived the pressure without major scares and Ross forced MacDonald into two saves in a comfortable second period for the nine men, although McCallum headed over from the best chance following Hamill's cross.
The first two penalties, from Shinnie and McCallum, were well saved before the outfield players found their range. But Brill saved Hamill's effort and Inverness kept their nerve before Draper sent MacDonald the wrong way to start the celebrations.