Metal-organic frameworks (MOFs) have emerged as highly versatile materials with applications in gas storage and separation, solar light energy harvesting and photocatalysis. The design of new MOFs, however, has been hampered by the lack of computational methods for ab initio crystal structure prediction, which could be used to direct experimental synthesis. Here we report the first ab intio method for MOF structure prediction, and test it against a diverse set of MOFs, with differences in topology, metal coordination geometry and ligand binding sites. In all cases our calculations produced structures which match experiment, proving the versatility of our procedure for MOF structure prediction. With our new methodology for ab initio structure prediction, current approaches to MOF design are set to change towards a more sustainable theory-driven materials development.