Ab initio calculations show an antiferromagnetic-ferromagnetic phase transition around 9-10 GPa and a magnetic anomaly at 12 GPa in BiFeO3. The magnetic phase transition also involves a structural and insulator-metal transition. The G-type AFM configuration under pressure leads to an increase of the y component and decrease of the z component of the magnetization, which is caused by the splitting of the dz2 orbital from doubly degenerate eg states. Our results agree with recent experimental results.