Peterhead ended their season with defeat as an injury time goal saw Dumbarton enhance their chances of avoiding the relegation play-off.
The Balmoor men led twice but were foiled by former Rothes attacker Jaime Wilson’s last-ditch winner.
With a massive incentive to win, Dumbarton looked the sharper of the sides in the opening stages and deservedly went ahead on 21 minutes.
As the Blue Toon looked to break forward, keeper Lenny Wilson sent a punt upfield only for the ball to be returned where it came from, catching the visiting defence on the hop.
Jaime Wilson was first to react for the home side and, racing through on goal, the striker kept his cool and slotted the ball behind his namesake and into the bottom corner from outside the area.
The loss of a goal sparked Peterhead into life and saw them create several chances of their own, one of which brought the leveller.
On 34 minutes Andy McCarthy sent a pinpoint cross into the Sons box and Steven Boyd had a simple header from close-range to leave Sam Ramsbottom helpless.
With both sides having decent spells towards the start and the end of the first 45 minutes, they found themselves level at 1-1 going into half-time.
James Wallace might have restored Dumbarton’s advantage before the break but his 14-yard shot went narrowly over.
The same player had an effort from outside the box on the restart but again it was too high.
Dumbarton, though, continued to press and went close again when dead-ball specialist Ross Forbes sent a 25-yard free kick inches over.
But the next goal came at the other end and it was similar to Peterhead’s first goal, this time veteran striker Derek Lyle producing the headed finish from Kieran Freeman’s accurate delivery.
Lyle almost gave the Balmoor men breathing space two minutes later with a 20-yard shot that whistled wide.
Jaime Wilson had a firm shot blocked in a busy box as the hosts attempted to restore parity and throw themselves a lifeline to dodge the play-off.
And their second equaliser came 10 minutes from time when Morgyn Neill got on the end of a Forbes corner to head home.
Scott Brown had a shot blocked as Peterhead attempted to go ahead for a third time but the winner came at the other end when Jaime Wilson notched his second with a header from a Forbes cross.
It was a disappointing end for the Blue Toon but Dumbarton will now be safe if Clyde fail to beat East Fife on Thursday night.