Rudi Skacel struck in the 93rd minute to earn Hearts a crucial 3-2 victory over St Mirren at Tynecastle.
Michael Higdon had twice given the visitors the lead, but they were pegged back by Ryan Stevenson and Skacel, whose second of the game ended a three-match winless run.
While Hearts remain in third place, St Mirren have now climbed six points clear of bottom-placed Hamilton.
Dundee United guaranteed a top-six finish with a 1-0 win over Inverness Caledonian Thistle at Tannadice. Danny Swanson's left-footed strike earned all three points for the hosts as they gained revenge for a 4-0 defeat against the same opponents in August.
John Sutton's opener was comprehensively cancelled out by goals from Manuel Pascali, Jamie Hamill and Liam Kelly as Kilmarnock beat Motherwell 3-1 in the early kick-off at Rugby Park.
Hamilton's long wait for a first home win of the season continues after they drew 0-0 with St Johnstone.