Short answer
Charles II of Spain (1661–1700) is generally considered the most inbred Spanish king. He was the last Habsburg to rule Spain, and he died childless, which ended the dynasty’s Spanish line.
Why the Habsburgs intermarried
Marriage was a political tool. The Habsburgs, who ruled both Spain and Austria, repeatedly married within the family to keep territory, titles and alliances in the dynasty’s hands. Uncle–niece and first-cousin marriages were common. Charles II’s father, Philip IV, married his niece Mariana of Austria, so Charles’s parents were already closely related, and many of his ancestors appear more than once in his family tree.
Charles II’s health and reputation
Contemporaries described Charles as sickly from childhood. He was reportedly slow to walk and talk, had difficulty eating and suffered frequent illness. Spaniards nicknamed him “El Hechizado,” meaning “the Bewitched,” because some believed his troubles had a supernatural cause. He married twice but had no children, and he died at 38.
What research suggests, and its limits
A 2009 genetic study based on the Habsburg pedigrees estimated that Charles’s inbreeding coefficient was high, roughly equal to that of a child of two siblings. The authors also suggested that two rare genetic conditions might explain some of his symptoms. That is an informed interpretation rather than a certain diagnosis, since the evidence is historical records and not his DNA. Other factors, such as poor medical care of the era, may also have contributed.
What happened after his death
Charles named a Bourbon, Philip of Anjou, as heir. The decision led to the War of the Spanish Succession, and Philip eventually became Philip V, founding the Bourbon line that still reigns today. For the full sequence of rulers, see our list of Spanish monarchs, and for more on the family as a whole, the Habsburg royal dynasty.