From lodestone to compass card
Lodestone, a naturally magnetised iron ore, was known in China and around the Mediterranean long before anyone steered by it. Early Chinese accounts treat it as a curiosity or as part of divination boards. The first clear description of a magnetised needle that points south, and of the fact that it does not point exactly south, is in Shen Kuo's Dream Pool Essays, written around 1088.
In Europe the earliest mention of a needle used by sailors is in a work by Alexander Neckam, an English scholar writing around 1190. By the thirteenth century the device was common on Mediterranean ships. The first versions were a magnetised needle pushed through a straw or a splinter of wood and floated in a bowl of water, which was awkward in a rolling ship.
The card
The change that made the compass a navigational instrument was to mount the needle on a pivot under a circular card marked with directions. The card turned with the needle, so the helmsman could read a heading straight off it instead of estimating an angle from a pointer. Cards were divided into winds, at first eight, then sixteen, then thirty-two points, each with a name, and a ship's course was given as a point of the compass. North was commonly marked with a fleur-de-lis, a convention that survives on many compass roses.
The pivoted card has no known single inventor. The popular attribution to Flavio Gioja of Amalfi, around 1300, rests on a source written long afterwards.
Variation
A needle does not point to the geographic pole. It follows the local magnetic field, and the angle between that direction and true north, the declination, differs from place to place and changes slowly over time. In the Mediterranean it was a small error. On Atlantic crossings it was harder to ignore: Columbus's log records that the offset of the needle from the pole star changed as he sailed west in 1492.
Declination was charted over the following centuries with limited success. Edmond Halley published a chart of lines of equal variation for the Atlantic in 1701, based on voyages he made for the purpose between 1698 and 1700. Lines of that kind are still printed on navigational charts.