Three-dimensional organic-inorganic perovskites have emerged as one of the most promising thin-film solar cell materials owing to their remarkable photophysical properties1-5, which have led to power conversion efficiencies exceeding 20 per cent6,7, with the prospect of further improvements towards the Shockley- Queisser limit for a single-junction solar cell (33.5 per cent)8. Besides efficiency, another critical factor for photovoltaics and other optoelectronic applications is environmental stability and photostability under operating conditions9-15. In contrast to their three-dimensional counterparts, Ruddlesden-Popper phases-layered two-dimensional perovskite films-have shown promising stability, but poor efficiency at only 4.73 per cent13,16,17. This relatively poor efficiency is attributed to the inhibition of out-of-plane charge transport by the organic cations, which act like insulating spacing layers between the conducting inorganic slabs. Here we overcome this issue in layered perovskites by producing thin films of near-single-crystalline quality, in which the crystallographic planes of the inorganic perovskite component have a strongly preferential out-of-plane alignment with respect to the contacts in planar solar cells to facilitate efficient charge transport. We report a photovoltaic efficiency of 12.52 per cent with no hysteresis, and the devices exhibit greatly improved stability in comparison to their three-dimensional counterparts when subjected to light, humidity and heat stress tests. Unencapsulated two-dimensional perovskite devices retain over 60 per cent of their efficiency for over 2,250 hours under constant, standard (AM1.5G) illumination, and exhibit greater tolerance to 65 per cent relative humidity than do three-dimensional equivalents. When the devices are encapsulated, the layered devices do not show any degradation under constant AM1.5G illumination or humidity. We anticipate that these results will lead to the growth of single-crystalline, solution-processed, layered, hybrid, perovskite thin films, which are essential for high-performance opto-electronic devices with technologically relevant long-term stability.