Defects at the surface and grain boundaries of metal–halide perovskite films lead to performance losses of perovskite solar cells (PSCs). Here, organic cyano-based π-conjugated molecules composed of indacenodithieno[3,2-b]thiophene (IDTT) are reported and it is found that their cyano group can effectively passivate such defects. To achieve a homogeneous distribution, these molecules are dissolved in the antisolvent, used to initiate the perovskite crystallization. It is found that these molecules are self-anchored at the grain boundaries due to their strong binding to undercoordinated Pb2+. On a device level, this passivation scheme enhances the charge separation and transport at the grain boundaries due to the well-matched energetic levels between the passivant and the perovskite. Consequently, these benefits contribute directly to the achievement of power conversion efficiencies as high as 21.2%, as well as the improved environmental and thermal stability of the PSCs. The surface treatment provides a new strategy to simultaneously passivate defects and enhance charge extraction/transport at the device interface by manipulating the anchoring groups of the molecules.