The kings of the Spanish Habsburg dynasty (1516-1700) frequently married close relatives in such a way that uncle-niece, first cousins and other consanguineous unions were prevalent in that dynasty. In the historical literature, it has been suggested that inbreeding was a major cause responsible for the extinction of the dynasty when the king Charles II, physically and mentally disabled, died in 1700 and no children were born from his two marriages, but this hypothesis has not been examined from a genetic perspective. In this article, this hypothesis is checked by computing the inbreeding coefficient (F) of the Spanish Habsburg kings from an extended pedigree up to 16 generations in depth and involving more than 3,000 individuals. The inbreeding coefficient of the Spanish Habsburg kings increased strongly along generations from 0.025 for king Philip I, the founder of the dynasty, to 0.254 for Charles II and several members of the dynasty had inbreeding coefficients higher than 0.20. In addition to inbreeding due to unions between close relatives, ancestral inbreeding from multiple remote ancestors makes a substantial contribution to the inbreeding coefficient of most kings. A statistically significant inbreeding depression for survival to 10 years is detected in the progenies of the Spanish Habsburg kings. The results indicate that inbreeding at the level of first cousin (F = 0.0625) exerted an adverse effect on survival of 17.8%+/-12.3. It is speculated that the simultaneous occurrence in Charles II (F = 0.254) of two different genetic disorders: combined pituitary hormone deficiency and distal renal tubular acidosis, determined by recessive alleles at two unlinked loci, could explain most of the complex clinical profile of this king, including his impotence/infertility which in last instance led to the extinction of the dynasty.