Since phages present a major challenge to survival in most environments, bacteria express a battery of anti-phage defences including CRISPR-Cas, restriction-modification and abortive infection systems 1-4 . Such strategies are effective, but the phage genome-which encodes potentially inhibitory gene products-is still allowed to enter the cell. The safest way to preclude phage infection is to block initial phage adsorption to the cell. Here, we describe a cell-surface modification that blocks infection by certain phages. Strains of the opportunistic pathogen Pseudomonas aeruginosa express one of five different type IV pilins (T4P) 5 , two of which are glycosylated with O-antigen units 6 or polymers of D-arabinofuranose 7-9 . We propose that predation by bacteriophages that use T4P as receptors selects for strains that mask potential phage binding sites using glycosylation. Here, we show that both modifications protect P. aeruginosa from certain pilus-specific phages. Alterations to pilin sequence can also block phage infection, but glycosylation is considered less likely to create disadvantageous phenotypes. Through construction of chimeric phages, we show that specific phage tail proteins allow for infection of strains with glycosylated pili. These studies provide insight into first-line bacterial defences against predation and ways in which phages circumvent them, and provide a rationale for the prevalence of pilus glycosylation in nature.