St Johnstone were cruelly denied promotion to the SPL after a final day of nerve-jangling drama.
Saints title hopes were undone by Gretna's late win
Saints swept into a three-goal lead through Kevin James, Martin Hardie and a cool solo effort from Jason Scotland.
Hamilton pulled one back through James McCarthy just before the break and Richard Offiong made it 3-2.
Hardie grabbed his second before Brian Wake's goal set up a tense finale but news then filtered through of Gretna's last-gasp win to crush Saints' dreams.
In front of a record crowd of 4,975 at New Douglas Park Saints had a storming start to the game and created several chances before James headed in a Paul Sheerin corner after 23 minutes.
A similar move nine minutes later doubled their lead when Hardie headed in after a James flick.
Jason Scotland ran on to a great through-ball from Peter Macdonald to net a third for the Perth side.
Highly-coveted teenager McCarthy pulled one back for Hamilton with a superb left-footed shot in the 40th minute.
Offiong made it 3-2 with a stunning 20-yard drive after 71 minutes as Hamilton continued to fight back.
However Hardie added his second goal of the afternoon following a Scotland pass, with substitute Brian Wake scoring a late third for Hamilton,
But it was the late Gretna winner against Ross County which broke St Johnstone hearts.
Hamilton: Murdoch, Parratt, Swales, McLauchlan (Winters 46), Easton, McCarthy, Wilson (Gilhaney 68), Gibson, McArthur, Offiong, McLeod (Wake 72).
Subs Not Used: McJimpsey, Jellema. Booked: McArthur.
Goals: McCarthy 40, Offiong 71, Wake 88.
St Johnstone: Cuthbert, Anderson, Lawrie, James, Stanic, Sheerin (McLaren 49), McInnes, Hardie, Mensing, MacDonald (Lilley 56), Scotland.
Subs Not Used: Jackson, Morais, Halliwell.
Goals: James 23, Hardie 32, Scotland 38, Hardie 81.
Ref: C Hardie (Scotland).