When an electric current passes near a compass, it changes position. The electric currents generate a magnetic field around them. This phenomenon was discovered by Öersted.