We use synchrotron x-ray and precision electron-diffraction techniques to determine accurately the structure factors of reflections that are sensitive to the valence-electron distribution in the superconductor MgB2. These values deviate significantly from those calculated using the scattering factors of free (or neutral) atoms, but agree well with our calculated structure factors based on density-functional theory. Having experimentally established the reliability of our first-principles-based structure factors, we present electron-density maps of the redistribution of the valence electrons that takes place when hypothetical free atoms of Mg and B in MgB2 interact to form the real crystal.