Grazing incidence X-ray diffraction has been used to determine the structure of two-dimensional organic-inorganic crystals formed of a behenic acid monolayer spread over a Mn2+ or Mg2+ solution at high pH. Using a new method based on careful structure factor determination, building of molecular models and simulated annealing, the number and position of the divalent ions in the unit cell, the orientation of the chain backbone planes and carboxylic headgroups conformation defects could be determined. In agreement with their bulk solution properties, Mn2+ and Mg2+ behave very differently. Individual Mn2+ ions adsorb below the negatively charged films, whereas the superstructure includes hydrolysis products containing one or several Mg2+ ions in the case of magnesium. This difference is also reflected in the kinetics of structure formation.