Abstract Climate change, especially through heatwaves, significantly affects human health and is a growing global concern. Concurrently, population aging is occurring worldwide, with many countries experiencing an increase in their elderly populations. As the elderly are particularly susceptible to extreme temperatures and unevenly distributed due to internal migration of younger populations, a spatio-temporal analysis integrating temperature changes and demographic data is essential. This study focuses on Japan, a super-aged society where over 25% of the total population is 65 years or older. We examined the effects of climate and the proportion of the elderly population on heatstroke deaths through spatio-temporal analysis within a Bayesian framework. We estimated the annual relative risk of heatstroke-related deaths at the prefecture level from 2008 to 2019. The results indicate a strong spatial autocorrelation in heatstroke deaths across Japan. The spatio-temporal interaction model was the best-performing, showing that regional and temporal variations significantly impact heatstroke mortality. In this model, a one-degree increase in temperature anomaly was linked to a 0.35 (95% CI 0.25 to 0.46) times higher odds of heatstroke deaths, while a 1% increase in the population aged 65 years or older was associated with 4.85 (95% CI 0.92 to 8.65) times higher odds. We found that not only metropolitan areas but also rural areas, such as the Tohoku and Shikoku regions, face a high risk of heatstroke, emphasizing the need to address the challenges in rural communities. Our study highlights the necessity of integrating temperature changes and demographic data in a spatio-temporal context for heatstroke risk assessment. It demonstrates the profound effects of temperature anomalies and the proportion of the elderly population on heatstroke mortality. This research framework could be applicable to other countries experiencing aging and heatwave issues, aiding in the development of targeted public health interventions.