A goalkeeping howler from Colin Doyle handed Motherwell a sixth consecutive Ladbrokes Premiership victory as David Turnbull's free-kick somehow found the net in stoppage time.
Turnbull's 25-yard strike looked to be harmlessly bouncing into Doyle's hands after substitute Ben Garuccio had been sent off for a lunging tackle on Liam Grimshaw. But the goalkeeper let the ball slip out of his hands and it spun behind him into the net.
It sealed a sixth top-flight win on the trot for Motherwell for only the second time in 82 years – the previous time they beat Hearts in 2014.
Steven Naismith looked to have earned Hearts a point with a sublime lob to level before the break after Jake Hastie gave Motherwell an early lead when he cut inside and fired another tremendous goal – his fourth in three matches.
It was an emotional afternoon at Fir Park as the home supporters paid first-half tributes to fellow fans Lloyd Welsh, 22, and Craig Frame, 44, following their sudden deaths in recent weeks.
After losing full-backs Michael Smith and Demetri Mitchell to injury last weekend, Hearts manager Craig Levein switched to a back three with Conor Shaughnessy coming in, and Marcus Godinho and Jake Mulraney installed as wing-backs.
Mulraney got forward to good effect down the left as Hearts made the brighter start but his intercepted forward pass led to Motherwell's 13th-minute opener.
Curtis Main flicked Allan Campbell's ball down the right into Hastie's path and the winger ran at pace at Christophe Berra before cutting inside the Hearts captain and unleashing a powerful strike high into the net from 16 yards.
Mulraney soon gifted the ball to Main but the striker shot off-target before Hastie forced a save from Doyle after Campbell's pass.
Hearts settled down and Oliver Bozanic had a 25-yard strike parried before they levelled in the 37th minute.
Uche Ikpeazu got outside of Tom Aldred and delivered a low cross which Naismith mis-kicked. But, with Richard Tait slipping as he tried to block, the coast was clear for the Scotland forward to loft the ball over Mark Gillespie's head from eight yards.
Sean Clare shot wide and Mulraney had a shot blocked in the goalmouth as Hearts finished the half well but Motherwell came out firing after the break.
Doyle saved well from Gboly Ariyibi after the winger burst through the Hearts defence and denied Hastie after Mulraney failed to deal with a diagonal ball. Levein instantly brought on left-back Garuccio for Shaughnessy and switched to a flat back four with Mulraney moved to the right wing.
Doyle made another good save from Turnbull before Garuccio cleared Main's header off the line.
Hearts threatened from two set-pieces but Gillespie stopped Ikpeazu's shot on the turn before Naismith blazed over at the back post.
Both teams pushed for a winner with Turnbull and John Souttar coming close at either end before the late drama.