The unique optoelectronic properties of black phosphorus (BP) have triggered great interest in its applications in areas not fulfilled by other layered materials (LMs). However, its poor stability (fast degradation, i.e. <<1 h for monolayers) under ambient conditions restricts its practical application. We demonstrate here, by an experimental-theoretical approach, that the incorporation of nitrogen molecules (N2) into the BP structure results in a relevant improvement of its stability in air, up to 8 days without optical degradation signs. Our strategy involves the generation of defects (phosphorus vacancies) by electron-beam irradiation, followed by their healing with N2 molecules. As an additional route, N2 plasma treatment is presented as an alternative for large area application. Our first principles calculations elucidate the mechanisms involved in the nitrogen incorporation as well as on the stabilization of the modified BP, which corroborates with our experimental observations. This stabilization approach can be applied in the processing of BP, allowing for its use in environmentally stable van der Waals heterostructures with other LMs as well as in optoelectronic and wearable devices.