Optical control of topology, particularly in the presence of electron correlations, is an interesting topic with broad scientific and technological impact1,2,3,4. Twisted MoTe 2 bilayer (tMoTe 2 ) is a zero-field fractional Chern insulator (FCI)5,6,7,8,9,10, exhibiting the fractionally quantized anomalous Hall effect11,12,13,14. As the chirality of the edge states and sign of the Chern number are determined by the underlying ferromagnetic polarization15,16, manipulation of ferromagnetism would realize control of the Chern insulator (CI)/FCI states. Here we demonstrate control of ferromagnetic polarization, and thus the CI and FCI states, by circularly polarized optical pumping in tMoTe 2 . At low excitation power, we achieve on-demand preparation of ferromagnetic polarization by optical training, that is, electrically tuning the system from non-ferromagnetic to desirable ferromagnetic states under helicity-selective optical pumping. With increased excitation power, we further realize direct optical switching of ferromagnetic polarization at a temperature far below the Curie temperature17,18. Both optical training and direct switching are most effective near CI and FCI states, which we attribute to a gap-enhanced valley polarization of optically pumped holes. The magnetization can be dynamically switched by modulating the helicity of optical excitation. Spatially resolved measurements further demonstrate optical writing of ferromagnetic, and thus CI (or FCI) domains. Our work realizes precise optical control of a topological quantum many-body system with potential applications in topological spintronics, quantum memories and creation of exotic edge states by programmable patterning of integer and fractionally quantized anomalous Hall domains4,19.