Advanced data-driven methods can outperform conventional features in electrocardiogram (ECG) analysis, but often lack interpretability. The variational autoencoder (VAE), a form of unsupervised machine learning, can address this shortcoming by extracting comprehensive and interpretable new ECG features. Our novel VAE model, trained on a dataset comprising over one million secondary care median beat ECGs, and validated using the UK Biobank, reveals 20 independent features that capture ECG information content with high reconstruction accuracy. Through phenome- and genome-wide association studies, we illustrate the increased power of the VAE approach for gene discovery, compared with conventional ECG traits, and identify previously unrecognised common and rare variant determinants of ECG morphology. Additionally, to highlight the interpretability of the model, we provide detailed visualisation of the associated ECG alterations. Our study shows that the VAE provides a valuable tool for advancing our understanding of cardiac function and its genetic underpinnings.