The embattled Edinburgh club, bottom of the Premiership and in administration off the field were held to a 1-1 draw after extra time at Stark's Park but eventually prevailed, Brad McKay scoring the decisive spot-kick.
Championship side Raith had taken the lead in the 50th minute when Liam Fox fired in following good work from Calum Elliot.
A Jamie Hamill penalty levelled the scores 12 minutes later after Jason Thomson brought down Billy King inside the area.
Hamill was also involved in the incident that led to Hill being red-carded on 74, the Raith player being shown a straight red card after appearing to aim a head-butt at his opponent.
After a goal-less extra-time period, Hearts twice wasted the chance to settle the tie when Jason Holt and David Smith failed to convert before McKay won it at the third attempt.