Jamie Walker and Sam Nicholson combined to rescue Hearts and earn a third successive victory for the Edinburgh club.
Ali Crawford, the former Hearts youth player, put visitors Hamilton ahead early in the second half before Walker's header and penalty and Nicholson's late goal brought Hearts their third win in a row.
It also increased Hamilton's winless run in Gorgie, which will now reach a 40th year. Their last victory at Tynecastle was in October 1977 although they looked capable of ending that sequence when Crawford volleyed them into the lead.
Walker's intervention was crucial, as was that of substitute Nicholson. It was from Nicholson's cross that Walker headed the equaliser, and Nicholson then drew the foul from which his colleague scored the decisive penalty. A cute late flick for Hearts' third goal was the icing on the cake for the winger.
The home players entered the match high on confidence after wins against Inverness and Partick Thistle. A pre-match minute's silence honoured the recent passing of former Tynecastle director Robert Wilson. With Walker starting in place of Nicholson, Hearts set out to attack from kick-off. Much of their early threat came down the right side as full-back Callum Paterson charged forward at will.
Hamilton goalkeeper Remi Matthews held shots from Walker and Tony Watt inside the opening 15 minutes. There was also a crucial sliding challenge from the visiting defender Georgios Sarris to deny Conor Sammon in the act of shooting.
Already without skipper Michael Devlin due to a knee problem, Accies then lost another defender, Daniel Seaborne, to injury after 18 minutes. Teenager Shaun Want stepped off the substitutes bench to replace him and make his senior debut.
Paterson continued to enjoy a free reign down the right with none of the Lanarkshire players tracking his runs. From his umpteenth scamper forward, his through pass found Sammon for a lay to Watt, but again Matthews held the low attempt at goal.
Watt caused trouble every time he collected the ball and ran at opponents. However, he was cautioned for diving on 30 minutes after hitting the ground when going past Want. Hamilton then threatened at the opposite end through the lively striker Alex D'Acol. His shot was smothered by a block tackle from John Souttar.
Hearts fans' frustration increased when Sammon sprinted on to a through ball but shot wide of target from around 12 yards. Paterson then stepped forward for a vicious swerving effort from 25 yards which rose only centimetres above Matthews' crossbar. There was also a 35-yarder from the other Hearts full-back, Faycal Rherras, which flew wide before the interval.
The second period took on a different complexion once the visitors took the lead. Five minutes after the restart, full-back Grant Gillespie evaded his marker on the left and crossed for Crawford to cushion a perfect first-time finish into the net with the inside of his right foot. The diminutive midfielder set off to celebrate in front of the small pocket of travelling fans in the Roseburn Stand.
Hearts responded with a volley from Walker which cannoned back off the post, but generally they were struggling to break Hamilton's resistance. Nicholson and Bjorn Johnsen were introduced as substitutes and Nicholson soon conjured a cross which led to the equaliser. His delivery from the right flank was met on the run by Walker for a powerful header from 12 yards, which Matthews got a hand to but could not stop.
The hosts pushed relentlessly for a winning goal thereafter. Paterson moved up front, had one header cleared off the line and another volley pushed round the post by Matthews. Every challenge in the Hamilton penalty area prompted howls for a penalty from the home support as Accies continued defending desperately.
Eventually, the breakthrough arrived inside the final ten minutes. Nicholson sprinted into the penalty area and was fouled by Want. Referee Craig Thomson pointed to the spot and, after some arguing involving both sets of players, Walker stepped up to win the game for Hearts with a calm finish low to Matthews' right.
In stoppage-time, Nicholson controlled a cross and impishly flicked it into the far corner of the net. A third goal made sure of victory on a day when Hearts' credentials got a stern examination.
Hearts (4-4-2): Hamilton; Paterson, Souttar, Rossi, Rherras; Cowie, Djoum, Kitchen, Walker; Sammon, Watt.
61: Nicholson for Djoum
61: Johnsen for Sammon
70: Muirhead for Watt
Unused subs: Noring, Ozturk, Buaben, L Smith.
Hamilton (4-1-4-1): Matthews; Lyon, Seaborne, Sarris, Gillespie; Donati; Imrie, MacKinnon, Docherty, Crawford; D'Acol.
18: Want for Seaborne
54: Bingham for D'Acol
76: Redmond for Docherty
Unused subs: Thomson, Kurtaj, Longridge, Brophy.
Referee: Craig Thomson.