We have carried out constant pressure ab initio simulations to study the pressure-induced phase transition of silicon. The diamond to beta-Sn phase change under hydrostatic pressure is successfully observed in the simulation. The transformation is based on a fourfold coordinated tetragonal intermediate state having the space group I4(1)/amd. The energy barrier for the transformation is calculated to be about 0.35 eV/atom. Additionally, we investigate the influence of nonhydrostatic compressions on the phase transition of silicon and find that up to 20% stress deviations, silicon converts to a beta-Sn structure with a reduced transition pressure. The triaxial compressions cause more reduction in the transition pressure than the uniaxial compressions. The transformation mechanism is practically identical under both hydrostatic and nonhydrostatic conditions.