Magnetotactic bacteria are widespread aquatic microorganisms that use unique intracellular organelles to navigate along the Earth's magnetic field. These organelles, called magnetosomes, consist of membrane-enclosed magnetite crystals that are thought to help to direct bacterial swimming towards growth-favouring microoxic zones at the bottom of natural waters. Questions in the study of magnetosome formation include understanding the factors governing the size and redox-controlled synthesis of the nano-sized magnetosomes and their assembly into a regular chain in order to achieve the maximum possible magnetic moment, against the physical tendency of magnetosome agglomeration. A deeper understanding of these mechanisms is expected from studying the genes present in the identified chromosomal 'magnetosome island', for which the connection with magnetosome synthesis has become evident. Here we use gene deletion in Magnetospirillum gryphiswaldense to show that magnetosome alignment is coupled to the presence of the mamJ gene product. MamJ is an acidic protein associated with a novel filamentous structure, as revealed by fluorescence microscopy and cryo-electron tomography. We suggest a mechanism in which MamJ interacts with the magnetosome surface as well as with a cytoskeleton-like structure. According to our hypothesis, magnetosome architecture represents one of the highest structural levels achieved in prokaryotic cells.