Computing the electronic structure of molecules with high precision is a central challenge in the field of quantum chemistry. Despite the success of approximate methods, tackling this problem exactly with conventional computers remains a formidable task. Several theoretical1,2 and experimental3,4,5 attempts have been made to use quantum computers to solve chemistry problems, with early proof-of-principle realizations done digitally. An appealing alternative to the digital approach is analogue quantum simulation, which does not require a scalable quantum computer and has already been successfully applied to solve condensed matter physics problems6,7,8. However, not all available or planned setups can be used for quantum chemistry problems, because it is not known how to engineer the required Coulomb interactions between them. Here we present an analogue approach to the simulation of quantum chemistry problems that relies on the careful combination of two technologies: ultracold atoms in optical lattices and cavity quantum electrodynamics. In the proposed simulator, fermionic atoms hopping in an optical potential play the role of electrons, additional optical potentials provide the nuclear attraction, and a single-spin excitation in a Mott insulator mediates the electronic Coulomb repulsion with the help of a cavity mode. We determine the operational conditions of the simulator and test it using a simple molecule. Our work opens up the possibility of efficiently computing the electronic structures of molecules with analogue quantum simulation.