In Gram staining, iodine plays a critical role as a mordant, a substance that fixes dyes in tissues. When iodine is applied after the crystal violet dye, it forms a complex with the dye molecules. This complex is larger and more insoluble, making it difficult for the dye to be washed out during the decolorization step. As a result, Gram-positive bacteria retain the purple color, while Gram-negative bacteria lose the dye and take up the counterstain.