Heidenheim overcame relegation rivals St. Pauli to give themselves a slim chance of pulling off a great escape.