Sodium-glucose cotransporter 2 inhibitors (SGLT2Is) may reduce nephrolithiasis risk by increasing urine flow. We aimed to investigate whether initiation of SGLT2I was associated with reduced nephrolithiasis risk. We conducted an active-comparator new-user cohort study using the Danish health registries in the period 11 November 2012 to 31 December 2018. Individuals aged ≥40years initiating SGLT2Is or glucagon-like peptide-1 receptor agonists (GLP1 RAs) were followed from treatment initiation until an inpatient or outpatient diagnosis of nephrolithiasis, death, emigration or end of study. New users of SGLT2Is were matched 1:1 on propensity scores to new users of GLP1 RAs. In supplementary analyses, risk of recurrent nephrolithiasis was assessed in individuals with a history of nephrolithiasis before treatment initiation. We identified 24,290 and 19,576 eligible users of SGLT2Is and GLP1 RAs, respectively. After matching, 12,325 patient pairs remained. The median age was 61years and median follow-up was 2.0years. The nephrolithiasis rate was 2.0 per 1000 person-years in SGLT2I initiators compared with 4.0 per 1000 person-years in GLP1 RA initiators, with a rate difference of -1.9 per 1000 person-years (95% CI -2.8, -1.0) and an HR of 0.51 (95% CI 0.37, 0.71). For recurrent nephrolithiasis (n = 731 patient pairs), the rate difference was -17 per 1000 person-years (95% CI -33, -1.5) and the HR was 0.68 (95% CI 0.48, 0.97). Initiation of treatment with SGLT2Is was associated with a clinically significant reduced risk of incident and recurrent nephrolithiasis.