Optical and synchrotron x-ray diffraction diamond anvil cell experiments have been combined with first-principles theoretical structure predictions to investigate mixtures of N2 and H2 up to 55 GPa. Our experiments show the formation of structurally complex van der Waals compounds [see also D. K. Spaulding et al., Nat. Commun. 5, 5739 (2014)] above 10 GPa. However, we found that these NxH (0.5 < x < 1.5) compounds transform abruptly to new oligomeric materials through barochemistry above 47 GPa and photochemistry at pressures as low as 10 GPa. These oligomeric compounds can be recovered to ambient pressure at T < 130 K, whereas at room temperature, they can be metastable on pressure release down to 3.5 GPa. Extensive theoretical calculations show that such oligomeric materials become thermodynamically more stable in comparison to mixtures of N2, H2, and NH3 above approximately 40 GPa. Our results suggest new pathways for synthesis of environmentally benign high energy-density materials. These materials could also exist as alternative planetary ices.