The forces governing the contrast in submolecular resolution imaging of molecules with atomic force microscopy (AFM) have recently become a topic of intense debate. Here, we show that the electrostatic force is essential to understand the contrast in atomically resolved AFM images of polar molecules. Specifically, we image strongly polarized molecules with negatively and positively charged tips. A contrast inversion is observed above the polar groups. By taking into account the electrostatic forces between tip and molecule, the observed contrast differences can be reproduced using a molecular mechanics model. In addition, we analyze the height dependence of the various force components contributing to the high-resolution AFM contrast.