Phase transitions can be used to alter the properties of a material without adding any additional atoms and are therefore of significant technological value. In a solid, phase transitions involve collective atomic displacements, but such atomic processes have so far only been investigated using macroscopic approaches. Here, we show that in situ scanning transmission electron microscopy can be used to follow the structural transformation between semiconducting (2H) and metallic (1T) phases in single-layered MoS2, with atomic resolution. The 2H/1T phase transition involves gliding atomic planes of sulphur and/or molybdenum and requires an intermediate phase (α-phase) as a precursor. The migration of two kinds of boundaries (β- and γ-boundaries) is also found to be responsible for the growth of the second phase. Furthermore, we show that areas of the 1T phase can be controllably grown in a layer of the 2H phase using an electron beam.