Male or female (sex assigned at birth, inclusive of all gender identities).
Age 18-75 years (both inclusive) at the time of signing the informed consent.
Diagnosed with type 2 diabetes greater than or equal to (≥) 180 days before screening.
Stable daily dose(s) ≥ 90 days before screening of the following antidiabetic drug(s) or combination regimen(s) at effective or maximum tolerated dose as judged by the investigator:
metformin with or without sodium-glucose cotransporter-2 (SGLT2) inhibitor.
HbA1c of 7.0-10.5 percent (%) (53-91 millimoles per mole (mmol/mol)) (both inclusive) as assessed by central laboratory at screening.
Body mass index between 25.0 kg/m\^2 and 50.0 kg/m\^2 (both inclusive) at screening.
Uncontrolled and potentially unstable diabetic retinopathy or maculopathy. Verified by an eye examination performed within 90 days before screening or in the period between screening and randomisation. Pharmacological pupil-dilation is a requirement unless using a digital fundus photography camera specified for non-dilated examination.
Known hypoglycaemic unawareness as indicated by the investigator according to Clarke's questionnaire, question 8.