Tuberculosis (TB) remains a global leading cause of death, necessitating an investigation into its unequal distribution. Sun exposure, linked to vitamin D (VD) synthesis, has been proposed as a protective factor. This study aimed to analyse TB rates in Spain over time and space and explore their relationship with sunlight exposure. An ecological study examined the associations between rainfall, sunshine hours, and TB incidence in Spain. Data from the National Epidemiological Surveillance Network (RENAVE in Spanish) and the Spanish Meteorological Agency (AEMET in Spanish) from 2012 to 2020 were utilized. Correlation and spatial regression analyses were conducted. Between 2012 and 2020, 43,419 non-imported TB cases were reported. A geographic pattern (north-south) and distinct seasonality (spring peaks and autumn troughs) were observed. Sunshine hours and rainfall displayed a strong negative correlation. Spatial regression and seasonal models identified a negative correlation between TB incidence and sunshine hours, with a four-month lag. A clear spatiotemporal association between TB incidence and sunshine hours emerged in Spain from 2012 to 2020. VD levels likely mediate this relationship, being influenced by sunlight exposure and TB development. Further research is warranted to elucidate the causal pathway and inform public health strategies for improved TB control.