The East India Company started a factory in the town in the 18th century, but commerce had already decayed and the establishment was abandoned. In the early part of the 10th centuiy Brunei was only a resort for pirates and a market for the slave trade. During the 1840s Admiral (then Captain) Keppel and other officers of the British navy suppressed piracy in the neighborhood. Sarawak was handed over to Raja Brooke, and, after the capture and temporary occupation of Brunei by Sir Thomas Cochrane, Labuan was ceded to the British empire. From this island it was possible to exercise a certain control over the towns people, and a consul was stationed there to watch affairs.
Brunei formerly included the whole of northern Borneo and southern Palawan, and stretched down the west coast as far as Sambas. A great reduction of the extent of the territory was brought about by the cession on successive occasions of strips of territory to Sarawak and to the British North Borneo Company on condition of annual payments of money. In 1888 the state was placed under British protection. On the 2nd of January 1906 a treaty was made whereby the Sultan of Brunei agreed to hand over the general administration of his state to a British resident.
The territory was occupied by the Japanese from 1942 to 1945. He became ruler of an independent state in 1983.