Following pioneering work(1), solution-processable organic-inorganic hybrid perovskites-such as CH3NH3PbX3 (X = Cl, Br, I)-have attracted attention as light-harvesting materials for mesoscopic solar cells(2-15). So far, the perovskite pigment has been deposited in a single step onto mesoporous metal oxide films using a mixture of PbX2 and CH3NH3X in a common solvent. However, the uncontrolled precipitation of the perovskite produces large morphological variations, resulting in a wide spread of photovoltaic performance in the resulting devices, which hampers the prospects for practical applications. Here we describe a sequential deposition method for the formation of the perovskite pigment within the porous metal oxide film. PbI2 is first introduced from solution into a nanoporous titanium dioxide film and subsequently transformed into the perovskite by exposing it to a solution of CH3NH3I. We find that the conversion occurs within the nanoporous host as soon as the two components come into contact, permitting much better control over the perovskite morphology than is possible with the previously employed route. Using this technique for the fabrication of solid-state mesoscopic solar cells greatly increases the reproducibility of their performance and allows us to achieve a power conversion efficiency of approximately 15 per cent (measured under standard AM1.5G test conditions on solar zenith angle, solar light intensity and cell temperature). This two-step method should provide new opportunities for the fabrication of solution-processed photovoltaic cells with unprecedented power conversion efficiencies and high stability equal to or even greater than those of today's best thin-film photovoltaic devices.