In 1841, Malcolm sailed to China as Secretary of Legation with Plenipotentiary Henry Pottinger during the First Anglo-Chinese War. On 29 August 1842, British and Chinese officials signed the Treaty of Nanking, which ended the war and ceded Hong Kong to Britain. After the Daoguang Emperor's assent for the treaty arrived in Nanking on 15 September, Malcolm sailed for London the next morning on board the steamer "Auckland" with a copy for ratification by Queen Victoria. He was made a Companion of the Order of the Bath on 24 December. After Pottinger became the first Governor of Hong Kong, he appointed Malcolm as the first Colonial Secretary on 27 June 1843. Malcolm was also a justice of the peace and served there until November 1843.