A method for producing a P-N junction in a thin film photovoltaic cell comprising a deposition step in which are carried out successively: a layer of precursors of a photovoltaic material of type P or N, a barrier layer and a layer of precursors of a semiconducting material of type N or P, this deposition step being followed by an annealing step carried out with a supply of S and/or Se, this annealing step leading to the formation of an absorbing layer of the type P or N and of a buffer layer of type N or P and of a P-N junction at the interface between said layers.