Post-hoc analyses of clinical trials suggest that sodium-glucose cotransporter-2 inhibitors (SGLT-2i) lower the risk of hyperkalemia and facilitate the use of renin-angiotensin system inhibitors (RASi) in people with type 2 diabetes. Whether this is also observed in routine care is unclear. We investigated whether SGLT-2i lowered the risk of hyperkalemia and RASi discontinuation as compared to dipeptidyl peptidase 4 inhibitors (DPP-4i). Using the target trial emulation framework, we studied adults with type 2 diabetes (T2D) who started SGLT-2i or DPP-4i in Stockholm, Sweden (2014-2021). The outcomes were incident hyperkalaemia (potassium>5.0 mmol/L), mild hyperkalemia (potassium>5-≤5.5mmol/L) and moderate to severe hyperkalemia (potassium>5.5mmol/L). Among RASi users, we studied time to RASi discontinuation through evaluation of pharmacy fills. Cox regression with inverse probability of treatment weighting was used to estimate per-protocol hazard ratios (HRs). 29 849 individuals (15 326 SGLT-2i and 14 523 DPP-4i initiators) were included (mean age 66 years, 37% women). About one third of participants in each arm discontinued treatment within a year. Compared with DPP-4i, SGLT-2i use was associated with a lower rate of hyperkalemia (HR 0.77; 95% CI: 0.64-0.93), including both mild (0.76; 0.62-0.93) and moderate/severe (0.53; 0.40-0.69) hyperkalemia events. Of 19.116 participants that used RASi at baseline, 7% discontinued therapy. Initiation of SGLT-2i vs. DPP-4i was not associated with the rate of RASi discontinuation (0.97; 0.83-1.14). Results were consistent in intention-to-treat analyses and across strata of age, sex, cardiovascular comorbidity, and baseline kidney function. In patients with diabetes managed in routine clinical care, the use of SGLT-2i was associated with lower rates of hyperkalemia compared with DPP-4i. Possibly because of a relatively high rate of treatment discontinuations, this was not accompanied by higher persistence on RASi therapy.