Randomised clinical trials showed that compared with placebo, SGLT2 inhibitors and GLP-1 receptor agonists reduced risk of adverse cardiovascular events. The evidence base for the older antihyperglycaemic drug classes (DPP-4 inhibitors and sulfonylureas) is generally less well developed. Because most randomised trials evaluated one antihyperglycaemic medication versus placebo, a head-to-head comparative effectiveness analysis of the newer drug classes (SGLT2 inhibitors vs GLP-1 receptor agonists) or newer (SGLT2 inhibitors or GLP-1 receptor agonists) versus older (DPP-4 inhibitors or sulfonylureas) drug classes on risk of major adverse cardiovascular events (MACE) is not available. In this study, we aimed to evaluate the comparative effectiveness of incident use of SGLT2 inhibitors, GLP-1 receptor agonists, DPP-4 inhibitors, or sulfonylureas on risk of MACE. We first specified the protocol of a four-arm randomised pragmatic clinical trial and then emulated it using the health-care databases of the US Department of Veterans Affairs. We built a cohort of metformin users with incident use of SGLT2 inhibitors, GLP-1 receptor agonists, DPP-4 inhibitors, or sulfonylureas between Oct 1, 2016 and Sept 30, 2021, and followed up until Dec 31, 2022. We used the overlap weighting approach to balance the treatment groups using a battery of predefined variables and a set of algorithmically selected variables from high-dimensional data domains. Both intention-to-treat and per-protocol analyses (the latter estimated the effect of maintained use of the antihyperglycaemic throughout follow-up) were conducted to estimate risk of MACE-defined as a composite endpoint of stroke, myocardial infarction, and all-cause mortality. The final cohort consisted of 283 998 new users of SGLT2 inhibitors (n=46 516), GLP-1 receptor agonists (n=26 038), DPP-4 inhibitors (n=55 310), or sulfonylureas (n=156 134). In intention-to-treat analyses, compared with sulfonylureas, SGLT2 inhibitors, GLP-1 receptor agonists, and DPP-4 inhibitors were associated with lower risk of MACE (hazard ratio [HR] 0·77 [95% CI 0·74-0.80], 0·78 [0·74-0·81), and 0·90 [0·86-0.93], respectively). Both SGLT2 inhibitors and GLP-1 receptor agonists were associated with a lower risk of MACE when compared with DPP-4 inhibitors (HR 0·86 [0·82-0·89] and 0·86 [0·82-0·90], respectively). The risk of MACE between SGLT2 inhibitors and GLP-1 receptor agonists yielded an HR of 0·99 (0·94-1·04). In per-protocol analyses, compared with sulfonylureas, SGLT2 inhibitors, GLP1 receptor agonists, and DPP-4 inhibitors were associated with reduced risk of MACE (HR 0·77 [95% CI 0·73-0·82], 0·77 [0·72-0·82], and 0·88 [0·83-0·93], respectively). Both SGLT2 inhibitors and GLP-1 receptor agonists were associated with a lower risk of MACE when compared with DPP-4 inhibitors (HR 0·88 [0·83-0·93] and 0·88 [0·82-0·93], respectively). The risk of MACE between SGLT2 inhibitors and GLP-1 receptor agonists yielded an HR of 1·01 (0·94-1·07). Both SGLT2 inhibitors and GLP-1 receptor agonists were associated with reduced risk of MACE compared with DPP-4 inhibitors or sulfonylureas. DPP-4 inhibitors were associated with reduced risk of MACE compared with sulfonylureas. There was no statistically significant difference in risk of MACE between SGLT2 inhibitors and GLP-1 receptor agonists. The results provide evidence of the real-world comparative effectiveness of the four most commonly used second-line antihyperglycaemics and could guide choice of antihyperglycaemic therapy. US Department of Veterans Affairs and the American Society of Nephrology.