In the Hall effect a voltage develops across a metal plate in the direction jxB, when a current j flows across a magnetic field B. Ferromagnetic metals display a Hall effect even in the absence of an applied magnetic field. The origin of this anomalous Hall effect (AHE) remained controversial for many decades. Recently it has been proposed that the AHE arises from a geometric phase factor acquired by the wave function of an electron as it moves through the crystal under an applied electric field. Although the physical picture is simple enough, the sign and magnitude of the effect depend in an intricate way on the electronic structure of the material. After reviewing the phenomenology and physical principles of the AHE, I will describe the key role played by first-principles calculations in validating the geometric-phase mechanism. When using conventional ab-initio methods the needed calculations are exceedingly demanding. I will explain how they can be performed rather efficiently by representing the electronic structure in terms of localized Wannier orbitals.