After an absence of nearly two years, during which he visited Celebes, and other parts of the Archipelago, Brooke returned to Sarawak on August 29th, 1840, only to find the country in a worse state than ever, for, encouraged by their repeated successes, the enemy had advanced to within thirty miles of Kuching. The poor Raja received him with open arms, and implored his assistance, offering to make over the country to him if he would only give him his help. Brooke, conceiving quite a friendship for the poor man, who, with all his faults was kind-hearted and sincere, now determined to do so, and organised an expedition against the enemy, headed by himself in person.

After months of hardship and privation, during which time he was several times deserted by his faint-hearted followers, Brooke succeeded in his efforts, and peace was restored on December 20th, 1840.

Although hostilities were now over, and danger past, Muda Hasim did not forget the promise he had made Brooke concerning the country in his adversity, and a form was drawn up by him for the signature of the Sultan of Brunei. The terms of this document were not, however, quite in accordance with what the Raja had undertaken to do, but this being pointed out to him by Brooke, he replied that the paper was merely a preliminary, and it would come to the same thing in the end. With this explanation Brooke had to be content, and await the return of the deed from Brunei.

Like all Easterns, Malays are most dilatory, and time hung very heavily on Brooke's hands at Kuching. Although the Raja was then (and ever after) a firm friend to Brooke, the native chiefs who surrounded him were not best pleased at the turn affairs were taking, and did their utmost, secretly, to undermine his influence with the people.

These intrigues were carried to such a dangerous extent by a certain Pangeran Makota (who had formerly been Governor of Sarawak, and the chief cause of the troubles in the interior, by his acts of cruelty and oppression), that Brooke determined to act forthwith, and bring matters to a crisis. Loading the Royalist's guns, and bringing them to bear, he went ashore with an armed party to the Raja's palace, and at once pointed out to him Pangeran Makota's treachery. He went on to say that Makota's presence in the country was dangerous both to the safety of the Raja and the Government, and announced his determination of expelling him from it. Brooke concluded by saying that a large force of Dyaks were at his call, and the only way to prevent bloodshed was to instal him Governor then and there.

This speech, and the determined way in which it was spoken, decided Muda Hasim. Brooke's terms were unconditionally accepted, and Makota outlawed. An agreement was signed by the Raja making over the government of Sarawak and its dependencies to Brooke, on his undertaking to pay a small annual tribute to the Sultan of Brunei, and this document having been duly signed by the latter, Brooke was proclaimed Raja of Sarawak on the 24th September, 1841.

From this day matters mended, and under the influence of a just government the country soon showed signs of improvement. In 1847 Raja Brooke went to England for a while, and was there received with great honours. Among others he received the order of knighthood while on a visit to Windsor Castle; and the freedom of the City of London was presented to him in recognition of his deeds in Borneo. He was not long away, however, from his adopted country, returning to Sarawak early the following year.

Sarawak now steadily progressed, and the revenue, which in the first year of Brooke's accession, was next to nothing, began to show a considerable increase. Several Englishmen also were employed by the Raja to maintain order throughout his dominions. An incident, however, occurred in 1857, which, had it not been for the prompt and decisive action shown by the Raja's Government, might have led to serious consequences.

A colony of Chinese (of whom great numbers had come into Sarawak on the accession of Sir James) had settled at Bau, a short distance above Kuching, on the Sarawak river, for the purpose of working gold. These men were members of a "Hue," or Chinese secret society, and, instigated by the three chiefs or leading members thereof, determined to attack Kuching, overthrow the Raja's government, and seize the country.

Descending the river in twenty-five large boats, some 600 strong, and fully armed, they reached the capital about midnight on the 18th of February. Their plan of attack had been carefully laid, and on arrival off the town they divided into two parties: the smaller of these turning up the Sungei Bedil, a small stream running close by the Government House, for the purpose of attacking it, and the larger proceeding down river to attack the fort situated on the opposite bank. Sir James Brooke had already been warned by some Malays that an attack was to be made by the gold-workers on Kuching, but knowing how prone natives are to exaggeration, had given the report no credence.