Mono- and multi-layered molybdenum disulfide (MoS2) is considered to be one of the next generation anode materials for rechargeable ion batteries. Structural transformation from trigonal prismatic (2H) to octahedral (1T) upon lithium or sodium intercalation has been in-situ observed experimentally using transmission electron microscope during studies of their electrochemical dynamics processes. In this work, we explored the fundamental mechanisms of this structural transformation in both mono- and bi-layered MoS2 using density functional theory. For the intercalated MoS2, the Li and Na donate their electrons to the MoS2. Based on the theoretical analysis, we confirmed that, for the first time, electron transfer is dominant in initiating this structural transformation, and the results provide an in-depth understanding of the transformation mechanism induced by the electron doping. The critical values of electron concentrations for this structural transformation are decreased with increasing the layer thickness.