In 1838, British adventurer (and budding imperialist) James Brooke helped the sultan put down a rebellion from warlike inland tribes. As a reward, the sultan granted Brooke power over part of Sarawak, which in hindsight was a big mistake.
Appointing himself Raja Brooke, James Brooke pacified the tribespeople, eliminated the much-feared Borneo pirates and forced a series of ‘treaties’ onto the sultan, whittling the country away until finally, in 1890, it was actually divided in half. This situation still exists today – if Bruneians want to get to the Temburong district, they have to go through Sarawak.