Tom Robson opened the scoring for Queen's Park in the fifth minute with a low effort.
Two quick goals in the second half saw Peterhead take the lead when Hamish Ritchie found the bottom corner and substitute Derek Lyle tucked the ball home minutes later.
The Spiders began to recover when Luca Connell scored from the edge of the box and Thomson got the winner in the 80th minute for his side to stay top.
The result saw Queen's Park extend their lead over Dumbarton, who had to settle for a 1-1 draw against Alloa, to two points.
Steven Boyd's strike helped Alloa take the lead just before half-time but Paddy Boyle rescued a point for the home side, heading in a corner 10 minutes from time.
Morgyn Neill scored in the 89th minute for Cove Rangers to beat Airdrie 1-0 and stay third in the table.
Michael Ruth also had to find a late goal for Falkirk to draw 2-2 with Montrose.
Graham Webster missed a penalty in the 23rd minute but went on to score a brace for Montrose in the second half to put his side 2-0 up.
Aidan Keena sparked the comeback for the Bairns in the 79th minute before Ruth tapped home the equaliser with seconds left on the clock.
Ross Cunningham also scored a brace in the second half for Clyde to beat bottom-of-the-table East Fife 2-0.