Injectisomes are multi-protein transmembrane machines allowing pathogenic bacteria to inject effector proteins into eukaryotic host cells, a process called type III secretion. Here we present the first three-dimensional structure of Yersinia enterocolitica and Shigella flexneri injectisomes in situ and the first structural analysis of the Yersinia injectisome. Unexpectedly, basal bodies of injectisomes inside the bacterial cells showed length variations of 20%. The in situ structures of the Y. enterocolitica and S. flexneri injectisomes had similar dimensions and were significantly longer than the isolated structures of related injectisomes. The crystal structure of the inner membrane injectisome component YscD appeared elongated compared to a homologous protein, and molecular dynamics simulations documented its elongation elasticity. The ring-shaped secretin YscC at the outer membrane was stretched by 30-40% in situ, compared to its isolated liposome-embedded conformation. We suggest that elasticity is critical for some two-membrane spanning protein complexes to cope with variations in the intermembrane distance. DOI:http://dx.doi.org/10.7554/eLife.00792.001.