R-type pyocins, produced by Pseudomonas aeruginosa, are sheath-tube nanomachines that puncture the envelopes of target cells, inducing their death. Cryo-EM studies reveal the atomic structures of the pyocin R2 in its extended precontraction and postcontraction forms, which suggest a mechanism for the contraction process of this molecular syringe.