Inclusion Criteria: - 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 Japan only: Male or female, age above or equal to 20 years at the time of signing informed consent. - Diagnosed with type 2 diabetes mellitus 90 days or more prior to the day of screening. - HbA1c (glycosylated haemoglobin) of 7.0-9.5% (53-80 mmol/mol) (both inclusive). - Stable treatment with one of the following insulin regimens (minimum 10 IU/day) 90 or more days prior to the day of screening. Maximum 20% change in total daily dose is acceptable: (1) Basal insulin alone or (2) Basal and bolus insulin in any combination or (3) Premixed insulin including combinations of soluble insulins Exclusion Criteria: - 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 Greece only: adequate contraceptive measures are defined as combined hormonal contraception (containing oestrogen and progesterone), which suppress ovulation (oral, intravaginal, percutaneous), progesterone-only hormonal contraception which suppress ovulation (oral, injectable, implantable), intrauterine device, hormone-releasing intrauterine system, bilateral tubal occlusion, partner with vasectomy, sexual abstinence. For Japan only: Adequate contraceptive measures are abstinence (not having sex), diaphragm, condom (by the partner), intrauterine device, sponge, spermicide or oral contraceptives. For Canada only: adequate contraceptive measures are defined as combined hormonal contraception (containing oestrogen and progesterone), which suppress ovulation (oral, intravaginal, percutaneous), progesterone-only hormonal contraception which suppress ovulation (oral, injectable, implantable), intrauterine device, hormone-releasing intrauterine system, bilateral tubal occlusion, partner with vasectomy, sexual abstinence - 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 (MEN 2) or Medullary Thyroid Carcinoma (MTC). - History of pancreatitis (acute or chronic). - History of major surgical procedures involving the stomach and potentially affecting absorption of trial product (e.g. subtotal and total gastrectomy, sleeve gastrectomy, gastric bypass surgery). - Any of the following: myocardial infarction (MI), stroke or hospitalisation for unstable angina or transient ischaemic attack within the past 180 days prior to the day of screening and randomisation. - Classified as being in New York Heart Association (NYHA) Class IV. - Planned coronary, carotid or peripheral artery revascularisation known on the day of screening. - Renal impairment defined as estimated Glomerular Filtration Rate (eGFR) less than 60 mL/min/1.73 m\^2 as per Chronic Kidney Disease Epidemiology Collaboration formula (CKD-EPI). - 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 change of insulin treatment for acute illness for a total of 14 days or less. - Known hypoglycaemic unawareness according to Clarke's questionnaire. - 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). - Subjects with alanine aminotransferase (ALT) more than 2.5 x upper normal limit (UNL).