Stacking order can influence the physical properties of two-dimensional van der Waals materials1,2. Here we applied hydrostatic pressure up to 2 GPa to modify the stacking order in the van der Waals magnetic insulator CrI3. We observed an irreversible interlayer antiferromagnetic-to-ferromagnetic transition in atomically thin CrI3 by magnetic circular dichroism and electron tunnelling measurements. The effect was accompanied by a monoclinic-to-rhombohedral stacking-order change characterized by polarized Raman spectroscopy. Before the structural change, the interlayer antiferromagnetic coupling energy can be tuned up by nearly 100% with pressure. Our experiment reveals the interlayer ferromagnetic ground state, which is established in bulk CrI3 but not observed in native exfoliated thin films. The observed correlation between the magnetic ground state and the stacking order is in good agreement with first principles calculations3-8 and suggests a route towards nanoscale magnetic textures by moiré engineering3,9.