Integration of the upconversion effect in perovskite solar cells (PSCs) is a facile approach towards extending the spectral absorption from the visible to the near infrared (NIR) range and reducing the non-absorption loss of solar photons. However, the big challenge for practical application of UCNCs in planar PSCs is the poor compatibility between UCNCs and the perovskite precursor. Herein, we have subtly overcome the tough compatibility issue using a ligand-exchange strategy. For the first time, β-NaYF4:Yb,Er UCNCs have been embedded in situ into a CH3NH3PbI3 layer to fabricate NIR-enabled planar PSCs. The CH3NH3I-capped UCNCs generated from the ligand-exchange were mixed with the perovskite precursor and served as nucleation sites for the UCNC-mediated heteroepitaxial growth of perovskite; moreover, the in situ embedding of UCNCs into the perovskite layer was realized during a spin-coating process. The resulting UCNC-embedded perovskite layer attained a uniform pinhole-free morphology with enlarged crystal grains and enabled NIR absorption. It also contributed to the energy transfer from the UCNCs to the perovskite and electron transport to the collecting electrode surface. The device fabricated using the UCNC-embedded perovskite film achieved an average power-conversion efficiency of 18.60% (19.70% for the best) under AM 1.5G and 0.37% under 980 nm laser, corresponding to 54% and 740-fold increase as compared to that of its counterpart without UCNCs.