But the Lions rode their luck, with Anthony Pilkington striking a shot from 25 yards which hit the crossbar in the eighth minute.
Millwall should have gone in front five minutes before the break when Marc Laird's header from Lewis Grabban's cross was brilliantly saved by Owain fon Williams.
James Tunnicliffe saved the day for Stockport five minutes into the second half when he scrambled Neil Harris' effort off the goalline after fon Williams had dropped Grabban's shot.
Harris was upended on the edge of the penalty area 16 minutes from time by Dominic Blizzard to hand Millwall a free-kick in a dangerous position.
Substitute Martin kept his focus while Stockport's wall argued with referee Iain Williamson before coolly smashing his shot beyond fon Williams for the only goal of the game.