Current peatland models generally lack dynamic feedback between the plant community structure and the environment, although the vegetation dynamics and ecosystem functioning are tightly linked. Realistic projections of peatland response to climate change requires including vegetation dynamics in ecosystem models. In peatlands, <i>Sphagnum</i> mosses are key engineers. The species composition in a moss community varies primarily following habitat moisture conditions. Hence, modelling the mechanisms in controlling the habitat preference of Sphagna is a good first step for modelling the community dynamics in peatlands. In this study, we developed the Peatland Moss Simulator (PMS), a process-based model, for simulating community dynamics of the peatland moss layer that results in habitat preferences of <i>Sphagnum</i> species along moisture gradients. PMS employed an individual-based approach to describe the variation of functional traits among shoots and the stochastic base of competition. At the shoot-level, growth and competition were driven by net photosynthesis, which was regulated by hydrological processes via capitulum water retention. The model was tested by predicting the habitat preferences of <i>S. magellanicum</i> and <i>S. fallax</i>, two key species representing dry (hummock) and wet (lawn) habitats in a poor fen peatland (Lakkasuo, Finland). PMS successfully captured the habitat preferences of the two <i>Sphagnum</i> species, based on observed variations in trait properties. Our model simulation further showed that the validity of PMS depended on the interspecific differences in capitulum water retention being correctly specified. Neglecting the water-retention differences led to the failure of PMS to predict the habitat preferences of the species in stochastic simulations. Our work highlights the importance of capitulum water retention to the dynamics and carbon functioning of <i>Sphagnum</i> communities in peatland ecosystems. Studies of peatland responses to changing environmental conditions thus need to include capitulum water processes as a control on the vegetation dynamics. For that our PMS model could be used as an elemental design for the future development of dynamic vegetation models for peatland ecosystems.