Paul Paton was the hero for Mixu Paatelainen's men as his spectacular 88th minute winner cut the gap on second-bottom Kilmarnock to 11 points with a game in hand.
Guy Demel had put Paatelainen's side ahead a minute before the interval only for Jamie Walker to level for Robbie Neilson's visitors after 48 minutes.
Hearts had Jordan McGhee sent off after 40 minutes for picking up a second yellow card while the hosts had substitute Henri Anier dismissed in the dying minutes, also for a second yellow, just after Paton's dramatic winner.
The hosts started well and after 17 minutes were denied the lead by some breathtaking goalkeeping
Scott Fraser's corner was met by Edward Ofere whose downward header brought a superb diving save from Neil Alexander who turned the ball round the post for a corner.
On the half hour, Blair Spittal's cross picked out Ofere again and his free header produced another fine stop from Alexander.
Hearts had barely been seen in an attacking sense until the 38th minute when Sam Nicholson drove forward to unleash a shot which went just wide of Eiji Kawashima's left hand post.
With 40 minutes gone the visitors were reduced to 10 men.
McGhee, who a few minutes earlier had been booked for a foul on Florent Sinama Pongolle, earned a second booking for a reckless challenge on Ofere,
This gave the hosts a lift and with 43 minutes gone John Rankin cut inside and hit a curling shot which came back off the inside of Alexander's post before bouncing to safety.
But a minute before the interval they got their just reward as Spittal's corner found Demel and he made no mistake by rising to plant a free header beyond the reach of Alexander for his first goal since joining the club
Hearts could not be any worse after the break and they proved so by equalising just three minutes into the second half.
United defender Coll Donaldson gave the ball away and John Souttar played it over the top for the on-rushing Walker who fired an unstoppable left shot high into Kawashima's top left hand corner
United went within inches of regaining the lead after 68 minutes when Paton's through ball was perfect for substitute Ryan Dow
He lobbed the advancing Alexander but had to watch as his effort bounced inside the six yard box and then over the bar
The hosts pushed hard for a winner and with 88 minutes gone Paton struck a superb 30-yard volley to seal three points.
United's celebrations were somewhat dampened when substitute Anier was sent off for a second yellow card.
Source : PA