The Ruhr valley club scored three times in the second half to battle back and open up a five-point lead at the top of the second division table with one game remaining, guaranteeing them a top-two finish.
- Don't have ESPN? Get instant access
A brace from Igor Matanovic gave the visitors a 2-0 lead by the 17th minute but Schalke wasted several chances to cut the deficit through forward Terodde.
The league's top scorer quickly made amends after the break, scoring twice in the 47th and 71st to draw the hosts level.
Their comeback was complete seven minutes later when Rodrigo Zalazar thundered his shot in off the crossbar nine minutes from the end.
St Pauli finished the game with nine men when Marcel Beifus was sent off for a foul in the 81st and Matanovic followed him in stoppage time.
Schalke are on 62 points, with Hamburg SV and Darmstadt 98 on 57. Werder Bremen, in fourth are also on 57 and face Aue on Sunday.
St Pauli's own hopes of promotion are now extremely slim with the team in sixth on 54. The top two win automatic promotion while the third-placed team go into a playoff.