The results of first-principles calculations of the electronic structure and the electron-phonon interaction in MgB2 are used to study theoretically the temperature dependence and anisotropy of the magnetic-field penetration depth. The effects of impurity scattering are essential for a proper description of the experimental results. We compare our results with experimental data and we argue that the two-band model describes the data rather well.