The Mariners went a goal down with just five minutes on the clock as Caolan Lavery gave the hosts the advantage.
But they worked their way back into the game and equalised three minutes before the break through Elliott Whitehouse.
Town then took the lead with James Hanson’s header on 68 minutes before the striker made the points safe with a late penalty.