The present Portuguese Naval School was created in the 18th century as the Royal Academy of the Midshipmen (Academia Real dos Guardas-Marinhas).
In 1782, the Company of Midshipmen (Companhia dos Guardas-Marinhas) was created to frame and train the midshipmen (naval officer candidates) of the Portuguese Navy. The Company of Midshipmen was installed in the building of the Naval Arsenal of Lisbon.
The Royal Academy of the Midshipmen was created in 1792, as a university-level naval academy. This Academy integrated the already existing Company of Midshipmen as its student corps.
In 1807, the Army of Napoleon invaded Portugal. In order not to be captured by the Napoleonic forces and maintain the independence of the Kingdom, the Portuguese Royal Court and government are transferred to the Portuguese colony of Brazil, continuing to rule from there. The Royal Academy of the Midshipmen and its Company of Midshipmen also embark in the naval fleet that carries the Royal Court to Brazil and are installed in Rio de Janeiro, in 1808.
In 1823, one year following the independence of Brazil, the faculty and the students of the Academy of the Midshipmen had to choose either the Brazilian or the Portuguese nationality. Those that chose the Portuguese nationality returned to Portugal and the others remained in Brazil. Then, two academies come into existence: the Imperial Academy of Midshipmen (Academia Imperial dos Guardas-Marinhas) in the Empire of Brazil (that would become the present Brazilian Naval School) and the Royal Academy of Midshipmen in the Kingdom of Portugal.
The Portuguese Royal Academy of Midshipmen was reorganized in 1845, becoming the Naval School (Escola Naval).