Understanding the behavior of molecular systems under pressure is a fundamental problem in condensed matter physics. In the case of nitrogen, the determination of the phase diagram and in particular of the melting line, are largely open problems. Two independent experiments have reported the presence of a maximum in the nitrogen melting curve, below 90 GPa, however the position and the interpretation of the origin of such maximum differ. By means of ab initio molecular dynamics simulations based on density functional theory and thermodynamic integration techniques, we have determined the phase diagram of nitrogen in the range between 20 and 100 GPa. We find a maximum in the melting line, related to a transformation in the liquid, from molecular N_2 to polymeric nitrogen accompanied by an insulator-to-metal transition.