Yogyakarta Palace was built by Prince Mangkubumi in 1755-1756 (Javanese year: 1682), several months after the signing of the Treaty of Giyanti between Prince Mangkubumi of Yogyakarta, Hamengkubuwono of Surakarta and Dutch East India Company. A Banyan Forest was chosen as the site of the palace due to its location between two rivers which were considered good protection from possible flooding.
On 20 June 1812, Stamford Raffles led a 1,200-strong British force to attack the walled royal city of Yogyakarta. The Javanese, although outnumbering the invader, weren't prepared for the attack and were taken back by the event. In one day the city of Yogyakarta fell and the royal palace was sacked and burned. The total loot from the palace valued £15,000 in gold, jewels and hard currency (which values £500,000 today). The event was the first time an attack has been carried out into a court in Java and as a result the sultanate was completely subjugated to colonial authority.
Most of the palace's current form are built by Sultan Hamengkubuwono VIII who reign from 1921 to 1939. It suffered from an earthquake in 1876 and 2006, and was subsequently rebuilt after the devastation.