Dartford took the lead through Jack Evans midway through the first half and looked to be heading towards recording a league double over the Mariners, having won at Blundell Park in October.
But Town hit back through Cook, before Thomas struck with two minutes to go to complete the comeback and move the club ten points clear of sixth-placed Hereford with three games left to play.
The Mariners were reduced to ten men for the closing stages when Joe Colbeck was sent off in added time but they were able to see out the remainder of the game and record another vital win.
Five changes were made to the Town side that salvaged a draw with a last-minute equaliser against Southport on Saturday.
Cleveland Taylor, who grabbed that leveller, was back in the starting line-up, while midfielders Craig Disley and Derek Niven both returned from injury.
Bradley Wood and Lennell John-Lewis were the others to come in as Thomas, Shaun Pearson, Marcus Marshall, Frankie Artus and Ross Hannah all missing out.
James McKeown started in goal, with Sam Hatton, Ian Miller, Tom Naylor and Wood forming the defence.
Taylor started on the right of the four-man midfield, with Disley and Niven in the centre and Colbeck on the left.
Cook partnered John-Lewis in attack, with Artus, Hannah and Thomas joining Liam Hearn and Dayle Southwell on the Grimsby bench.
Town had a setback in the first minute when Miller suffered a cut in a clash of heads and had to go off.
The Mariners continued with ten men until the sixth minute, when Thomas was sent on in Miller’s place, with the substitute slotting into an unfamiliar centre-back role.
Dartford created the better of the early opportunities, with Charlie Sheringham having a shot blocked by Naylor from the edge of the penalty area.
The striker and son of former England star Teddy Sheringham then hit another shot from 30 yards, which McKeown had to stop.
Town saw a Taylor cross blocked on 13 minutes before another cross from Colbeck fell for Cook but the ball was cleared by the home defence.
A free kick gave the Mariners a chance to put some pressure on the Dartford goal on 23 minutes but Colbeck’s delivery was punched clear by home keeper Csaba Somogyi.
Two minutes later, Town fell behind as the hosts opened the scoring. Striker Nathan Collier’s shot was blocked but midfielder EVANS picked the ball up and saw his deflected shot find the net from inside the box.
Cook went close with a header from 12 yards soon afterwards as the Mariners looked to hit back but Somogyi was there to make the catch.
A foul on Disley near the halfway line gave Town a chance to get the ball into an attacking area but McKeown’s ball from the free kick was too far for Cook and it went out for a goal kick.
A shot from Niven flew well over the bar on 39 minutes, before a deep cross from John-Lewis did not lead to a chance in front of goal.
McKeown had to be at his best to prevent the home side from going 2-0 ahead when Sheringham pounced on a ball inside the box but the keeper made the block.
A Dartford corner led to Evans shooting from the edge of the box on 42 minutes but the effort was blocked and Town cleared.
Cook was fouled inside the Darts half and Mark Arber was booked for it before a push by Naylor on Tom Bonner delayed the free kick. Hatton tried a shot from 35 yards with the set piece and it was deflected for a corner, which Colbeck sent out for a goal kick.
Another yellow card was shown to left back Adam Green for a foul on Taylor as the half moved into stoppage time. Hatton’s ball into the box was headed out as far as Niven, who sent a shot wide.
That was the last meaningful action of the first half, meaning the Mariners were behind at the interval.
No further substitutions were made before the restart and Sheringham had the first chance of the second half for the hosts, although his long-range effort bounced up for McKeown.
Town’s first opportunity of the half came when John-Lewis almost got on the end of a cross from Taylor on one flank before meeting a Colbeck ball from the opposite side with an acrobatic shot that missed the target.
Cook hit a low effort that keeper Somogyi claimed at the second attempt with John-Lewis looking to pounce on any rebound.
Hatton had to concede a corner at the other end five minutes in and Thomas headed it away before a volley from James Rogers flew over the bar.
McKeown had to dive to stop a 25-yard shot from Sheringham as Dartford kept up their spell of pressure.
A free kick from Hatton for Town on 53 minutes eventually fell for Colbeck but his effort went past the post.
Another chance fell for John-Lewis after a quick break by the Mariners led to Colbeck crossing for the striker, who put his header at Somogyi.
Town were beginning to threaten and Somogyi was forced into action again to stop a header from Cook at the far post just after the hour.
Southwell replaced Taylor as Grimsby made their second change, before they were forced into another swap when Niven pulled up injured and had to be replaced by Artus.
Another Town chance came when Colbeck flashed a ball across from the right on 71 minutes but neither Cook nor John-Lewis could make the necessary contact to divert it into the net.
Lee Noble replaced Jon Wallis for Dartford, before boss Tony Burman used his other two substitutions to send Danny Harris and Jason Prior on in place of Sheringham and Collier.
The Mariners had their equaliser with 11 minutes to go, when a free kick given for a foul by Noble was curled into the danger zone by Artus and COOK met it to head past the keeper and into the net.
Dartford could have reclaimed their lead almost immediately when McKeown had to make a save to give the home side a corner, which then led to captain Elliott Bradbrook heading over the bar.
An opportunity for the Mariners to win the game came with five minutes to go as Southwell got on the end of a floated cross but could not direct his header towards goal.
Colbeck then had a shot blocked after a Thomas cross was helped on by Cook.
Grimsby did not have long to wait before they were celebrating though, as a corner from Artus on 88 minutes was met by THOMAS to head home his first goal for the club.
Four added minutes were signalled and the game ended on a sour note when Colbeck was shown a straight red card for an altercation with left-back Green before a throw-in.
But the ten men remaining on the field for the Mariners held on for the final two minutes of the game to secure all three points.
Town are next in action on Friday, when they travel to Luton Town.