Ross County and Kilmarnock can both look forward to Premiership football against next season, with Motherwell now facing the play-offs.
Ross County came from behind to beat Hamilton 2-1 in Dingwall after Lucas Tagliapietra had given Accies the lead. Michael Gardyne equalised and Liam Boyce grabbed the winner with five minutes left after Filip Kiss had been sent off for the Staggies.
Kilmarnock ended their poor run of results in style, beating Partick Thistle 4-1 at Firhill. Tope Obadeyi bagged a double and Jamie Hamill and Josh Magennis were also on target for Gary Locke's men, with Conrad Balatoni replying for the Jags.
Motherwell went down 2-1 to relegated St Mirren in Paisley despite going ahead through John Sutton's 75th-minute penalty. Jason Naismith equalised and Stevie Mallan got the winner deep into stoppage time after Well striker Scott McDonald had been red carded.
Third-placed Inverness CT saw off Dundee United 3-0 in the Highlands thanks to second-half goals from Josh Meekings, Nick Ross and Gary Warren.
Adam Rooney claimed an injury-time equaliser for Aberdeen at Dens Park in a 1-1 draw against Dundee, who had gone ahead through Luka Tankulic.