Psilocybin, the natural hallucinogen produced by Psilocybe (“magic”) mushrooms, holds great promise for the treatment of depression and several other mental health conditions. The final step in the psilocybin biosynthetic pathway, dimethylation of the tryptophan-derived intermediate norbaeocystin, is catalysed by PsiM. Here we present atomic resolution (0.9 Å) crystal structures of PsiM trapped at various stages of its reaction cycle, providing detailed insight into the SAM-dependent methylation mechanism. Structural and phylogenetic analyses suggest that PsiM derives from epitranscriptomic N6-methyladenosine writers of the METTL16 family, which is further supported by the observation that bound substrates physicochemically mimic RNA. Inherent limitations of the ancestral monomethyltransferase scaffold hamper the efficiency of psilocybin assembly and leave PsiM incapable of catalysing trimethylation to aeruginascin. The results of our study will support bioengineering efforts aiming to create novel variants of psilocybin with improved therapeutic properties.