The visitors were up against it early on, with Miko Virtanen heading a strong Accies side in front.
The game came alive in the second half following a lengthy break in play before the interval.
Euan Henderson, who had troubled early on, fed Leo Watson who delivered a cross for Mackenzie Kirk to equalise around the hour mark.
Hearts went in front moments later when Aidan Denholm produced a sublime piece of play, driving forward from deep before rifling a shot into the corner.
The visitors could have went further ahead before Accies turned the game around with Lewis Spence and Andy Ryan scoring in the space of eight minutes.