On 27 October 1807, Spain's Prime Minister Manuel de Godoy signed the Treaty of Fontainebleau with France, by which in return for the alliance and passage of French armies through its realm, Spain would receive Portuguese territory. In November 1807, after the refusal of Prince Regent John of Portugal to join the Continental System, Napoleon sent an army into Spain under General Jean-Andoche Junot with the aim of invading Portugal (as well as the secret task of being the vanguard for the eventual French occupation of Spain). Napoleon soon embroiled himself and France in Spain's internal power struggles within its royal family, eventually leading to the Spanish populace turning on the French occupiers and the beginning of the Peninsular War.