St Mirren opened up a six-point lead at the top of the First Division but they were made to fight every inch of the way by bottom club Brechin.
The match got off to a sensational start and Brechin almost scored after 15 seconds. Kevin Byers crossed from the right and Gerry Britton headed against the crossbar.
St Mirren threatened after 12 minutes when Simon Lappin headed back a Charlie Adam free-kick and Brechin managed to clear.
Five minutes later a Mark Reilly shot from 20 yards was saved by Craig Nelson.
St Mirren went close after 25 minutes when a shot from Kirk Broadfoot was headed off the line by David White.
Two minutes later Steven Hampshire shot just wide for Brechin.
Brechin took the lead on the half-hour mark when Britton crossed from the left for Byers to head home.
St Mirren equalised five minutes later when a Lappin corner was headed on by Stewart Kean and John Sutton volleyed home.
Right on half-time a drive from Hampshire was just kept out by Chris Smith.
A minute into the second half a 25-yard shot from Stuart Callaghan was saved by Smith.
St Mirren took a 2-1 lead after 67 minutes when a long cross from Adam was headed home by Sutton.
Two minutes later it was 3-1when Kean held off two defenders and scored from the edge of the box.
Brechin got a goal back after 82 minutes when Charlie King crossed for Paul Ritchie to side-foot home.
Brechin almost equalised in stoppage time when Darren Smith was denied by keeper Chris Smith.