Sean Clare missed an early penalty for the visitors but Michael Smith opened the scoring and Conor Washington netted from the spot before the break.
Chris Long pulled one back for the Steelmen on the hour mark but Hearts held on to knock out their Premiership rivals for the second year running.