To begin building a biofilm, motile cells must adhere to a surface structure. However, the mechanisms by which cells sense and respond to surfaces are unclear. In Bacillus subtilis, several signalling pathways control biofilm formation, including the two-component system DegS–DegU. This study reveals that inhibition of flagellar rotation, which is likely to occur when a motile cell encounters a surface, activates DegS–DegU signalling. Mutation or deletion of the flagellar stator gene motB (which is required for flagellar rotation), as well as inhibition of flagellar rotation by tethering with antibodies or by inducing the flagellar clutch, EpsE, induced several cellular processes driven by phosphorylated DegU, including synthesis of the biofilm exoplymer poly-γ-DL-glutamic acid. These findings suggest that the arrest of flagellar rotation acts as a mechanosensory signal to facilitate the transition from a motile to a sessile state.