We present radiation-magneto-hydrodynamic simulations of star formation in selfgravitating, turbulent molecular clouds, modeling the formation of individual massive stars, including their UV radiation feedback. The set of simulations have cloud masses between m gas = 10 3 M to 3 × 10 5 M and gas densities typical of clouds in the local universe (n gas ∼ 1.8 × 10 2 cm −3 ) and 10× and 100× denser, expected to exist in high-redshift galaxies. The main results are: i) The observed Salpeter power-law slope and normalisation of the stellar initial mass function at the high-mass end can be reproduced if we assume that each star-forming gas clump (sink particle) fragments into stars producing on average a maximum stellar mass about 40% of the mass of the sink particle, while the remaining 60% is distributed into smaller mass stars. Assuming that the sinks fragment according to a power-law mass function flatter than Salpeter, with log-slope 0.8, satisfy this empirical prescription. ii) The star formation law that best describes our set of simulation is dρ * /dt ∝ ρ 1.5 gas if n gas < n cri ≈ 10 3 cm −3 , and dρ * /dt ∝ ρ 2.5 gas otherwise. The duration of the star formation episode is roughly 6 cloud's sound crossing times (with c s = 10 km/s). iii) The total star formation efficiency in the cloud is f * = 2%(m gas /10 4 M ) 0.4 (1 + n gas /n cri ) 0.91 , for gas at solar metallicity, while for metallicity Z < 0.1 Z , based on our limited sample, f * is reduced by a factor of ∼ 5. iv) The most compact and massive clouds appear to form globular cluster progenitors, in the sense that star clusters remain gravitationally bound after the gas has been expelled.