Inclusion Criteria:
Main phase (the inclusion criteria for the main phase are not reassessed for the extension phase):
- Informed consent obtained before any trial-related activities. Trial-related activities are any procedures that are carried out as part of the trial, including activities to determine suitability for the trial
- Male or female, age above or equal to 18 years at the time of signing informed consent. For Korea only: Male or female, age above or equal to 19 years at the time of signing informed consent
- Diagnosed with type 2 diabetes mellitus for at least 90 days prior to day of screening
- HbA1c (glycosylated haemoglobin) 7.5-9.5% (58-80 mmol/mol) (both inclusive)
- Treatment target of HbA1c below 7.0% (53 mmol/mol), as judged by the investigator
- Stable daily dose(s) of 1-2 of the following anti-diabetic drugs within 90 days prior to the day of screening:
- Metformin (equal or above 1500 mg or maximum tolerated dose as documented in the subject medical record)
- Sulfonylureas (equal or above half of the maximum approved dose according to local label or maximum tolerated dose as documented in subject medical record)
- Sodium glucose co-transporter 2 inhibitors
- Thiazolidinediones (equal or above half of the maximum approved dose according to local label or maximum tolerated dose as documented in subject medical record)
Extension phase:
- Informed consent for the extension phase obtained before any trial-related activities for the extension phase.
- On randomised treatment with or without rescue medication at week 52.
Exclusion Criteria:
Main phase (the exclusion criteria for the main phase are not reassessed for the extension phase):
- Female who is pregnant, breast-feeding or intends to become pregnant or is of child-bearing potential and not using an adequate contraceptive method (adequate contraceptive measure as required by local regulation or practice). For certain specific countries: Additional specific requirements apply
- Any disorder, which in the investigator's opinion might jeopardise subject's safety or compliance with the protocol
- Family or personal history of Multiple Endocrine Neoplasia Type 2 or Medullary Thyroid Carcinoma
- History of pancreatitis (acute or chronic)
- History of major surgical procedures involving the stomach potentially affecting absorption of trial product (e.g. subtotal and total gastrectomy, sleeve gastrectomy, gastric bypass surgery)
- Any of the following: myocardial infarction, stroke or hospitalisation for unstable angina or transient ischaemic attack within the past 180 days prior to the day of screening and randomisation
- Subjects presently classified as being in New York Heart Association Class IV
- Planned coronary, carotid or peripheral artery revascularisation known on the day of screening
- Subjects with alanine aminotransferase above 2.5 x upper normal limit
- Renal impairment defined as Estimated Glomerular Filtration rate 60 mL/min/1.73 m^2 as per Chronic Kidney Disease Epidemiology Collaboration formula
- Treatment with any medication for the indication of diabetes or obesity other than stated in the inclusion criteria in a period of 90 days before the day of screening. An exception is short-term insulin treatment for acute illness for a total of below or equal to 14 days
- Proliferative retinopathy or maculopathy requiring acute treatment. Verified by fundus photography or dilated fundoscopy performed within 90 days prior to randomisation
- History or presence of malignant neoplasms within the last 5 years (except basal and squamous cell skin cancer and carcinoma in situ)
- History of diabetic ketoacidosis
Extension phase: There are no new exclusion criteria for the extension phase