The trap states at grain boundaries (GBs) within polycrystalline perovskite films deteriorate their optoelectronic properties, making GB engineering particularly important for stable high-performance optoelectronic devices. It is demonstrated that trap states within bulk films can be effectively passivated by semiconducting molecules with Lewis acid or base functional groups. The perovskite crystallization kinetics are studied using in situ synchrotron-based grazing-incidence X-ray scattering to explore the film formation mechanism. A model of the passivation mechanism is proposed to understand how the molecules simultaneously passivate the Pb-I antisite defects and vacancies created by under-coordinated Pb atoms. In addition, it also explains how the energy offset between the semiconducting molecules and the perovskite influences trap states and intergrain carrier transport. The superior optoelectronic properties are attained by optimizing the molecular passivation treatments. These benefits are translated into significant enhancements of the power conversion efficiencies to 19.3%, as well as improved environmental and thermal stability of solar cells. The passivated devices without encapsulation degrade only by ≈13% after 40 d of exposure in 50% relative humidity at room temperature, and only ≈10% after 24 h at 80 °C in controlled environment.