It is critical for bacteria to recognize surface contact and initiate physiological changes required for surface-associated lifestyles. Ubiquitous microbial appendages called pili are involved in sensing surfaces and facilitating downstream behaviors, but the mechanism by which pili mediate surface sensing has been unclear. We visualized Caulobacter crescentus pili undergoing dynamic cycles of extension and retraction. Within seconds of surface contact, these cycles ceased, which coincided with synthesis of the adhesive holdfast required for attachment. Physically blocking pili imposed resistance to pilus retraction, which was sufficient to stimulate holdfast synthesis without surface contact. Thus, to sense surfaces, bacteria use the resistance on retracting, surface-bound pili that occurs upon surface contact.