In November 1807 the French army, led by General Jean-Andoche Junot, occupied Lisbon and invaded Portugal. In order to avoid the consequences of the French invasion, the Royal Court of Portugal left for the Portuguese colony of Brazil at almost the same time. Queen Mary of Portugal, the Prince Regent at the time, Dom João VI of Braganza, other members of the royal family, together with elements of the nobility, high clergy, Council of State and high courts, physicians, librarians, musicians, and even a riding master, fled to Rio de Janeiro, so that Napoleon would not be able to depose the House of Braganza from the throne. Many assets were also taken, namely the Royal Library, silver, jewels and a printing press. In March 1808, the court arrived in Rio de Janeiro.
With the partial evacuation of Lisbon and the lack of preparation of the Portuguese army, it was easy for Junot's army (of 25,000 soldiers) to occupy Lisbon. Initially he tried to rule Portugal without creating major conflicts, as he hoped, like Murat in Naples, to become the king of a new French satellite state. He attempted to gain the approval of the people by leaving almost untouched the judicial, fiscal and administrative structures and by giving privileges to the afrancesados (the pro-French Portuguese). He even tried to convince Napoleon to bestow a Constitution to Portugal as he had done in July 1807 to the Grand Duchy of Warsaw. In order to achieve this Junot convened, in May 1808, a traditional assembly which had not been functioning for more than a century, where the three main groups of Portuguese society (the nobility, the clergymen and the people) had seats. This Junta dos Três Estados begged Napoleon for a Constitution for the Portuguese Kingdom that would be a constitutional monarchy (whose king would be Junot), where the principle of equality before the law would be respected and the Napoleonic Civil Code applied.
But Portugal remained unappeased and the population resisted the French occupation. Junot altered his position, declared the Braganza dynasty officially deposed in February 1808, and dissolved the regency council. He began to adopt harsh reforms and the intensity of reaction of the population grew steadily: uprisings against the French occupation occurred all over the territory and local associations were created in order to resist foreign control.