Male or female (sex assigned at birth, inclusive of all gender identities).
Age 18 years or above at the time of signing the informed consent.
Diagnosed with type 2 diabetes mellitus (T2DM) greater than or equal to (≥) 180 days before screening.
Stable once-weekly dose ≥ 90 days before screening of branded s.c. semaglutide. Branded semaglutide s.c. includes Ozempic and Wegovy. Participants on compounded semaglutide are ineligible.
Not on treatment with oral antidiabetic drugs or on stable daily dose(s) ≥ 90 days before screening of any of the following antidiabetic drug(s) or combination regimen at effective or maximum tolerated dose (MTD) as judged by the investigator: metformin and/or sodiumglucose co-transporter-2 (SGLT2) inhibitor.
Glycated haemoglobin (HbA1c) 6.5-10.5 percentage (%) (48-91 millimoles per mole \[mmol/mol\]) (both inclusive) as determined by central laboratory at screening.
Body mass index (BMI) ≥ 25 kilograms per square meter (kg/m\^2) at screening. BMI will be calculated in the electronic case report form (eCRF) based on height and body weight 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.
A self-reported change in body weight \> 5% within 90 days before screening irrespective of medical records.
Use of personal continuous glucose monitoring (CGM) devices. Participants currently using personal CGM devices must discontinue use prior to screening and throughout study participation.
You may not be if
Female who is pregnant, breast-feeding or intends to become pregnant or is of childbearing potential and not using a highly effective contraceptive method from screening.
Renal impairment with estimated glomerular filtration rate (eGFR) less than (\<) 30 milliliter per minute per 1.73 square meter (mL/min/1.73 m\^2) as determined by central laboratory at screening.