MAGIC, a system of two imaging atmospheric Cherenkov telescopes, achieves its best performance under dark conditions, i.e. in absence of moonlight or twilight. Since operating the telescopes only during dark time would severely limit the duty cycle, observations are also performed when the Moon is present in the sky. Here we present a dedicated Moon-adapted analysis and characterize the performance of MAGIC under moonlight. We evaluate energy threshold, angular resolution and sensitivity of MAGIC under different background light levels, based on Crab Nebula observations and tuned Monte Carlo simulations. This study includes observations taken under non-standard hardware configurations, such as reducing the camera photomultiplier tubes gain by a factor $sim$1.7 (reduced HV settings) with respect to standard settings (nominal HV) or using UV-pass filters to strongly reduce the amount of moonlight reaching the telescopes cameras. The Crab Nebula spectrum is correctly reconstructed in all the studied illumination levels, that reach up to 30 times brighter than under dark conditions. The main effect of moonlight is an increase in the analysis energy threshold and in the systematic uncertainties on the flux normalization. The sensitivity degradation is constrained to be below 10%, within 15-30% and between 60 and 80% for nominal HV, reduced HV and UV-pass filter observations, respectively. No worsening of the angular resolution was found. Thanks to observations during moonlight, the duty cycle can be doubled, suppressing the need to stop observations around full Moon.