Sandakan grew in the 1870s on the bay of the same name, where traders dealt in birds' nests, timber, rattan and sea produce with the Sulu Sea. In 1883 it became the capital of British North Borneo, run by the British North Borneo Chartered Company, and its timber and trade made it one of the richest towns in Borneo.
During the Japanese occupation (1942–45) Allied prisoners of war were held at a camp outside the town. In 1945 most of them died on the Sandakan Death Marches to Ranau or in the camp — only six Australians survived, all by escaping. Allied bombing and fires destroyed the town, and after the war the capital moved to Jesselton, today's Kota Kinabalu. Sabah joined Malaysia in 1963.
Sandakan was rebuilt as a busy port town. The Sepilok Orangutan Rehabilitation Centre, opened in 1964 at the edge of the Kabili-Sepilok forest, made it the starting point for wildlife trips on Sabah's east coast.