Despite the notable progress in perovskite solar cells, maintaining long-term operational stability and minimizing potentially leaked lead (Pb2+) ions are two challenges that are yet to be resolved. Here we address these issues using a thiol-functionalized 2D conjugated metal-organic framework as an electron-extraction layer at the perovskite/cathode interface. The resultant devices exhibit high power conversion efficiency (22.02%) along with a substantially improved long-term operational stability. The perovskite solar cell modified with a metal-organic framework could retain more than 90% of its initial efficiency under accelerated testing conditions, that is continuous light irradiation at maximum power point tracking for 1,000 h at 85 °C. More importantly, the functionalized metal-organic framework could capture most of the Pb2+ leaked from the degraded perovskite solar cells by forming water-insoluble solids. Therefore, this method that simultaneously tackles the operational stability and lead contamination issues in perovskite solar cells could greatly improve the feasibility of large-scale deployment of perovskite photovoltaic technology.