A stoppage-time winner from Jonathan Franks condemned Hamilton to a bottom-two finish as Ross County moved up to seventh place with a 3-2 win in an action-packed clash at Global Energy Stadium.
Accies fought back twice to level after County had taken the early initiative, but a superb volley from Franks deep in stoppage time secured the points.
County took the lead after just three minutes when Christopher Routis' short corner led to Michael Gardyne cutting inside and curling a shot into the far top corner of the net.
It was mostly County but Accies threatened in the 10th minute when Ali Crawford tried to pick out Dougie Imrie in the box but Tim Chow made a timely tackle to concede a corner kick.
County were knocking it about well and a Kenny Der Weg cross was only partially cleared to Franks whose first-time shot flew just wide of Remi Matthews' right-hand post.
The home side were controlling things and Gardyne let fly from 25 yards but the Accies keeper made a comfortable save.
But the visitors got a goal out of nothing in the 26th minute when a Crawford free-kick was knocked down in a crowded box and Rakish Bingham blasted home from six yards.
Gardyne went off injured before the restart and was replaced by Martin Woods.
Accies almost took the lead in the 34th minute when Bingham fired against the inside of the post after Scott Fox had parried a Crawford shot after a spell of pressure from the visitors.
The County goal got another let-off a couple of minutes from the break when a Crawford free-kick rebounded off the other post before being cleared.
County forced a couple of corners in first-half stoppage time but the Accies defence got the ball away.
Woods failed to appear at the start of the second half and was replaced by Jim O'Brien in the County midfield.
Immediately from the kick-off, Reghan Tumilty broke into the Accies box but his angled drive was kept out by Matthews.
At the other end Ioannis Skondras tried his luck from range but Fox got down well at his near post to smother the shot.
Routis looked as if he was about to pull the trigger inside the box in the 59th minute but he was closed down and when it broke to Franks, his shot ballooned well over.
Routis was involved again three minutes later when the ball broke to him in the box but Matthews made a point-blank save.
Accies came close shortly afterwards when a Skondras cross picked out Greg Docherty at the back post but his shot was kept out on the line by Fox.
But it was County who restored their lead in the 73rd minute when O'Brien lashed the ball into the net off the inside of the post.
Accies refused to lie down, though, and David Templeton cut inside and drilled a low shot past Fox from an angle for the equaliser.
However, County grabbed a dramatic winner when Franks volleyed home from just outside the 18-yard box.