The attachment of bacteria to surfaces provides advantages such as increasing nutrient access and resistance to environmental stress. Attachment begins with a reversible phase, often mediated by surface structures such as flagella and pili, followed by a transition to irreversible attachment, typically mediated by polysaccharides. Here we show that the interplay between pili and flagellum rotation stimulates the rapid transition between reversible and polysaccharide-mediated irreversible attachment. We found that reversible attachment of Caulobacter crescentus cells is mediated by motile cells bearing pili and that their contact with a surface results in the rapid pili-dependent arrest of flagellum rotation and concurrent stimulation of polar holdfast adhesive polysaccharide. Similar stimulation of polar adhesin production by surface contact occurs in Asticcacaulis biprosthecum and Agrobacterium tumefaciens. Therefore, single bacterial cells respond to their initial contact with surfaces by triggering just-in-time adhesin production. This mechanism restricts stable attachment to intimate surface interactions, thereby maximizing surface attachment, discouraging non-productive self-adherence, and preventing curing of the adhesive.