We report the structure of methylammonium lead(II) iodide perovskite in mesoporous TiO2, as used in high-performance solar cells. Pair distribution function analysis of X-ray scattering reveals a two component nanostructure: one component with medium range crystalline order (30 atom %) and another with only local structural coherence (70 atom %). The nanostructuring correlates with a blueshift of the absorption onset and increases the photoluminescence. Our findings underscore the importance of fully characterizing and controlling the structure for improved solar cell efficiency.