Mycoplasma genitalium is a human pathogen adhering to host target epithelial cells and causing urethritis, cervicitis and pelvic inflammatory disease. Essential for infectivity is a transmembrane adhesion complex called Nap comprising proteins P110 and P140. Here we report the crystal structure of P140 both alone and in complex with the N-terminal domain of P110. By cryo-electron microscopy (cryo-EM) and tomography (cryo-ET) we find closed and open Nap conformations, determined at 9.8 and 15 Å, respectively. Both crystal structures and the cryo-EM structure are found in a closed conformation, where the sialic acid binding site in P110 is occluded. By contrast, the cryo-ET structure shows an open conformation, where the binding site is accessible. Structural information, in combination with functional studies, suggests a mechanism for attachment and release of M. genitalium to and from the host cell receptor, in which Nap conformations alternate to sustain motility and guarantee infectivity.