The Spanish monarchy entered crisis during the Abdications of Bayonne, when the Mutiny of Aranjuez forced king Charles IV to abdicate and give the throne to his son, Ferdinand VII. Napoleon Bonaparte, whose troops were in Spain en route to Portugal, forced Ferdinand to abdicate as well, ending Bourbon rule and appointing his brother Joseph Bonaparte as monarch. This was the start of the Peninsular War, the Spanish resistance to the French invasion. Spain was already divided between the enlightenment and the absolutists, but the French invasion divided the ideas even more. The Enlightenment was based in the ideas of the French revolution, but it was the French themselves who were invading the country. The Spanish afrancesados supported the French invasion as a way to remove the absolutist Spanish monarchy and replace it with a liberal monarchy, even if a foreign one. A higher portion of the enlightened Spanish rejected such a perspective, and opposed both the French invasion and an absolutist restoration. San Martín was part of this group.