In 1700 Charles II, the last king of the House of Habsburg, died. When he died without children, the War of Succession began, which pitted the defenders of the House of Habsburg with the followers of the House of Bourbon. The Austracists supported that the Austrian Archduke Charles should be the next king of Spain, while the Bourbons were with the French Philip of Anjou.
The war lasted 14 years and ended with the signing of the Treaty of Utretcht, which confirmed Philip of Anjou as Philip V of Spain. The House of Bourbon arrived in Spain. The Bourbon kings carried out French-style reforms, centralizing the state.
With the Nueva Planta Decrees (and as a punishment for having supported the Habsburgs during the War of Succession), Felipe V abolished the charters, laws and institutions that the Crown of Aragon had had for more than 400 years. The administrative system of the Crown of Castile was imposed for all of Spain. Power was centralized in Madrid, from where a government of secretaries directed the entire Spanish Empire, which was divided into provinces. Philip V closed the Cortes, abolished the old Councils (except that of Castile) and controlled the legislative work.
Much less absolutist was Charles III, son of Philip V. He was influenced by the ideas of the enlightened Gaspar Melchor de Jovellanos (1744-1811) and adopted a series of reforms for the people, but without the opinion of the people. It is the definition of enlightened despotism: intellectuals decide what is best for the educated classes.
Charles III improved education and the economy, but his work was slowed down by the bloody French Revolution. Seeing that the enlightened ideas had cut off the head of the French king, the rest of the European monarchies decided to turn their backs on the Enlightenment and the reforms.