"We made a few changes today because we've been conceding horrendous goals, " said the Accies boss.
Rudi Skacel gave Hearts a 32nd-minute lead, dipping a volley towards the Accies goal from 18 yards out.
The Accies forward dispossessed Lee Cox, dribbled round a few players and cracked a left-foot shot into the net.
But Grainger snatched a win for Derek McInnes's team when his free-kick evaded the Accies defence and goalkeeper Tomas Cerny.
Immediately after the break, Templeton doubled the lead, firing the ball from distance into the top corner of the Accies net.
Earlier, Colin Nish had hit the Accies' crossbar with a strong header.
Steven Thomson then hit the Accies side-netting with a sterling opportunity as the hosts tried to battle their way back into the match.
But the Accies' form has dipped in recent weeks as they have dropped points and lost players through injury, a situation acknowledged by the Czech goalie.
Gallacher had to tip away Brian Easton's punt, which threatened to sneak in under the bar, but again there was no threat from the Accies corner.
BBC: Alex Neil (r) and Steven Thomson in action at St Mirren Park
The Accies charge petered out and, with Inverness looking comfortable thanks to their two-goal cushion, there was little in the way of goalmouth action in the closing stages.
With 30 minutes played, Craig Thomson fired a powerful shot wide of the Accies goal as the visitors went in search of a second goal at New Douglas Park.
With five minutes on the clock Gallacher mis-hit his kick straight to Simon Mensing, who passed to the Accies midfielder who somehow knocked the ball wide from just a few yards out.
BBC: Alex Neil (r) and Steven Thomson in action at St Mirren Park
Roy O'Donovan was thrust straight into the United line-up following his loan move from Sunderland and his excellent headed flick narrowly evaded the sliding Warren Feeney right in front of the Accies' goal.
Moments later, a low drive from Jim Goodwin was easily gathered by Saints keeper Graeme Smith, then Collin Samuel fired over the Accies bar from just outside the six-yard box at the other end.
Ryan Stevenson watched a late effort sail harmlessly over the Accies bar and Calum Elliot came close in the final minute, but the third goal wasn't required as Hearts easily claimed all three points.
The Accies, who have lost costly late goals in their last two league outings, are now two points clear of St Mirren, who prop up the league after the home defeat to Dundee United.
Maurice Edu's 11th-minute strike was enough to consign Hamilton to their first league defeat in seven matches, but the Accies boss is sure the linesman called it wrong when he ruled McArthur's late goal offside.
BBC: Hamilton worthy of Ibrox point believes boss Billy Reid
The Accies defence then somehow managed to escape going a goal down after Paddy McCourt cut the ball back across the Hamilton goal-line after a mazy run, but Mark McLaughlin blocked the shot from Forrest.
Eric Odhiambo showed a good turn of pace down the left as the match reached its final stages, but Mensing, in his 100th appearance for the Accies, was well positioned to head the Englishman's cross clear.
Celtic had the bulk of possession in the early part of the game, but found it hard to break down the Accies rearguard with the home side pressing Celtic players whenever they were on the ball.
McArthur puts their success down to the spirit of happiness within the squad inspired by manager Billy Reid and stressed that the Accies players always had a belief that they could hold their own in the top flight.
The Accies forward was caught out as Craig Conway found Dixon with his quickly taken set-piece and, when the full-back's low drive struck the legs of goalkeeper Cerny, Daly rose to head the high spinning ball into the net from five yards.
Ipswich Town boss Roy Keane and several English Premier League scouts were in attendance to keep an eye on James McCarthy and the Accies teenager was involved in an early chances, setting up Lyle for a shot that went wide of the mark.
Left-back James Gibson featured in central midfield, fellow 19-year-old Lucas Akins was given a rare start up front, while recent signing Trent McClenahan was given his first start as Reid attempted to plug the leaks that have bedevilled the Accies rearguard in recent weeks.
David Elebert could have claimed the points for Accies in the dying minutes, but his header inched wide.
BBC: Hamilton's David Elebert (left) tussles with Sone Aluko
The defeat means Accies remain at the foot of the table, having failed to win a home league game this season, while Hearts have now firmly cemented third place behind Rangers and Celtic.
As the impressive Accies tired, Tomas Cerny made excellent stops from Steven Davis and Nacho Novo.
Goalkeeper Scott Flinders touched Akins' shot onto the post before the striker missed an excellent chance to give Accies the lead.
应用推荐