This prognostic study developed and validated a machine-learning model using extensive Swedish and Finnish databases, identifying mortality risk in first-episode psychosis. For patients with predicted high risk, only long-acting injectable antipsychotics and mood stabilizers were associated with decreased mortality risk; among those with predicted low risk, oral aripiprazole and risperidone were associated with decreased mortality risk.