James Keating’s stunning opening goal was cancelled out by an Iain Russell spot-kick after Prince Buaben had struck a penalty against the post for the hosts.
But Robbie Neilson’s side kept their composure to secure maximum points as they regained the lead through skipper Danny Wilson before Buaben made amends for his earlier mistake as he fired home and Adam Eckersely added a fourth.
Hearts began well and went close after just three minutes, with Alim Ozturk forcing away keeper Zander Clark to save low down by his post.
Callum Paterson and Robbie Buchanan then combined well, with Paterson firing just past the post, but the opening goal was not long in coming.
A long ball upfield from Wilson was volleyed home left-footed by Keatings as the home side took the lead in dramatic fashion.
Hearts then spurned the opportunity to double the lead as Buaben saw his penalty come back off the post after Paterson was fouled in the area.
That looked as though it might prove costly as the away side drew level 11 minutes after the restart as Ian McShane was brought down in the area by Jamie Walker.
Russell stepped up to take the penalty and he showed Buaben how it should be done as he confidently stroked the ball past Hearts ‘keeper Neil Alexander.
The lead was to prove shortlived though, as the Jambos regained the lead. A Hearts corner came off Ozturk before the ball reached skipper Wilson, who headed home on 67.
Buaben then made amends for his earlier penalty miss by adding a third goal for Neilson’s side, the Ghanaian evading the attention of two defenders before firing into the corner of the net.
There was still time for a fourth Hearts goal which came courtesy of Eckersley, who advanced from his left-back position to curl a shot into the top corner.