Background: Hypertension is a leading modifiable risk factor for cardiovascular disease, yet a substantial proportion of affected individuals remain undiagnosed, particularly in low-resource settings. Early detection during middle age represents a critical opportunity for life-course cardiovascular prevention. We aimed to identify key predictors of undiagnosed hypertension among middle-aged adults in Tanzania using an explainable machine learning approach.Methods: We analysed nationally representative survey data from 2,547 adults aged 40–49 years with biomarker-measured blood pressure. Undiagnosed hypertension was defined as elevated measured blood pressure without prior professional diagnosis. Analyses incorporated survey sampling weights. A random forest model was developed and compared with multivariable logistic regression. Discrimination was assessed using area under the receiver operating characteristic curve (AUC), and interpretability was examined using Shapley Additive Explanations. Stratified analyses evaluated effect modification across socioeconomic and geographic subgroups.Findings: Overall, 15·4% of participants had undiagnosed hypertension, representing 61·0% of all hypertensive individuals. The random forest model demonstrated excellent discrimination (AUC 0·945, 95% CI 0·933–0·957), substantially outperforming logistic regression (AUC 0·623, 95% CI 0·571–0·633; p<0·0001). Age and body mass index were the strongest predictors, followed by wealth index, geographic zone, and health insurance status. Marked geographic heterogeneity was observed, with Zanzibar and Northern zones exhibiting the highest predicted probabilities.Interpretation: Undiagnosed hypertension is common among Tanzanian middle-aged adults, representing a major missed opportunity for early cardiovascular risk modification. Explainable machine learning enables accurate and transparent risk stratification and may inform targeted detection strategies to reduce cardiovascular disease burden in later adulthood.