Catalyzes the SAM-dependent triple methylation of the alpha-amino group of histidine to form hercynine, a step in the biosynthesis pathway of ergothioneine. Among all the proteinogenic amino acids, only L-histidine is a substrate. L-histidine + 3 S-adenosyl-L-methionine = 3 H(+) + hercynine + 3 S-adenosyl-L-homocysteine kcat is 0.58 sec(-1) for the methylation of L-histidine. kcat is 0.23 sec(-1) for the methylation of N-alpha-methyl-L-histidine. kcat is 0.23 sec(-1) for the methylation of N-alpha,N-alpha-dimethyl-L-histidine. Amino-acid biosynthesis; ergothioneine biosynthesis. Monomer. Consists of two distinct domains: a typical methyltransferase domain and a unique substrate binding domain. Cells lacking this gene are unable to synthesize ergothioneine (ERG), but do not show growth defect. Deletion of egtD from wild-type M.smegmatis and a mycothiol (MSH)-deficient mutant does not affect their susceptibility to tested antibiotics. The ERG- and MSH-deficient double mutant is significantly more sensitive to peroxide than either of the single mutants lacking either ERG or MSH, suggesting that both thiols play a role in protecting M.smegmatis against oxidative stress and that ERG is able to partly compensate for the loss of MSH. Belongs to the methyltransferase superfamily. EgtD family.