Magnetic deviation is the error induced in a compass by local magnetic fields, which must be allowed for, along with magnetic declination, if accurate bearings are to be calculated. (More loosely, "magnetic deviation" is used by some to mean the same as "magnetic declination". This article is about the former meaning.)
Compasses are used to determine the direction of true North. However, the compass reading must be corrected for two effects. The first is magnetic declination or variation, the angular difference between magnetic North (the local direction of the Earth's magnetic field) and true North. The second is magnetic deviation, the angular difference between magnetic North and the compass needle due to nearby sources of interference such as magnetically permeable bodies, or other magnetic fields within the field of influence.
The Earth's magnetic field is modified by local magnetic anomalies. These include variations of the magnetization in the Earth's crust caused by geomagnetic reversals as well as nearby mountains and iron ore deposits. Generally, these are indicated on maps as part of the declination. Because the Earth's field changes over time, the maps must be kept up to date for accurate navigation. Short term errors in compass readings are also caused by fields generated in the Earth's magnetosphere, particularly during geomagnetic storms.
In navigation manuals, magnetic deviation often refers specifically to compass error caused by magnetized iron within a ship or aircraft. This iron has a mixture of permanent magnetization and an induced (temporary) magnetization that is induced by the Earth's magnetic field. Because the latter depends on the orientation of the craft relative to the Earth's field, it can be difficult to analyze and correct for it.