The home side opened the scoring when Conor Wilkinson struck after just five minutes but the Mariners hit back through Luke Waterfall's header from a corner.
George Williams went on to give Town a half-time lead, before substitute Jordan Maguire-Drew levelled the scores with a little more than a quarter of an hour to go.
But the visitors were to have the final say as Owen Windsor was brought down inside the box as the game moved into added time and substitute Montel Gibson kept his nerve from 12 yards to find the net and ensure the points came back to North East Lincolnshire.
Town boss Ian Holloway made five changes to his starting line-up following the 3-1 win at Cheltenham on Tuesday.
Danny Rose, Williams, Terry Taylor, Matt Green and Windsor all came in, with Owura Edwards, James Tilley, James Morton, Gibson and Ludvig Ohman dropping out.
James McKeown began in goal, with Luke Hendrie, Mattie Pollock, Waterfall and Danny Preston forming a four-man defence.
Harry Clifton, Rose, Williams and Taylor were the midfielders, with Green and Windsor lining up in attack.
Edwards, Tilley, Morton and Gibson were all named as substitutes, along with Ollie Battersby, Duncan Idehen and Joe Starbuck.