Research on occupational accidents is a key factor in improving working conditions and sustainability. Fatal accidents incur significant human and economic costs. Therefore, it is essential to examine fatal accidents to identify the factors that contribute to their occurrence. This study presents an overview of fatal heart attack accidents at work in Spain over the period 2009–2021. Descriptive analysis was conducted considering 13 variables classified into five groups. These variables were selected as predictors to determine the occurrence of this type of accident using a machine learning technique. Thirteen Naïve Bayes prediction models were developed using an unbalanced dataset of 15,616 valid samples from the Spanish Delta@database, employing a two-stage algorithm. The final model was retained using a General Performance Score index. The model selected for this study used a 70:30 distribution for the training and test datasets. A sample was classified as a fatal heart attack if its posterior probability exceeded 0.25. This model is assumed to be a compromise between the confusion matrix values of each model. Sectors with the highest number of heart attacks are ‘Health and social work’, ‘Transport and storage’, ‘Manufacturing’, and ‘Construction’. The incidence of heart attacks and fatal heart attack accidents is higher in men than in women and higher in private sector employees. The findings and model development may assist in the formulation of surveillance strategies and preventive measures to reduce the incidence of heart attacks in the workplace.