In November 1793, Almeida was an adjutant general. He commanded Portuguese forces in Spain, fighting against the French. In 1798, he became the commander of a unit of light troops known as the Alorna Legion. Almeida was promoted to major general in 1799. He began conspiring with the French, and helped force the Portuguese court to flee to Brazil in 1807. He was promoted to lieutenant general in October of that year, and charged with the defense of Elvas. However, under the orders of the prince regent, he was forced to surrender Elvas to the Spanish on December 2, 1807.