Ma performed the Hajj in 1841, leaving China by a circuitous route; as ocean travel out of China had been disrupted by the Opium War, he chose instead to leave with a group of Muslim merchants travelling overland. After passing through Xishuangbanna, they went south to Burma, then took a riverboat along the Irrawaddy River from Mandalay to Rangoon. From Rangoon, they were able to board a steamship which took them all the way to the Arabian Peninsula. After his time in Mecca, he stayed in the Middle East for another eight years; he first went to Cairo, where he studied at Al-Azhar University, then travelled throughout the Ottoman Empire, going to Suez, Alexandria, Jerusalem, Istanbul, Cyprus, and Rhodes.