Things changed with the opening of the Anglo-Spanish War, and the threat of a British invasion upon the viceroyalty. The viceroy Antonio de Olaguer y Feliú negotiated a pardon with his family, on the condition that he joined the Corps of Blandengues with a hundred men, to form a battalion. Thus, he began his military career in 1797, at age 33, with the rank of lieutenant. The attack finally came in 1806, when William Beresford invaded Buenos Aires, in the first British invasion of the River Plate. Although Artigas's unit was tasked with patrolling the frontier with Brazil, he requested to take part in the military expedition that Santiago de Liniers launched from Montevideo to drive the British out of Buenos Aires. His request was granted, and the British were defeated. After the recapture of Buenos Aires, he was tasked with returning to Montevideo and informing the governor Pascual Ruiz Huidobro of the result of the battle. A second British invasion aimed to capture Montevideo, which was captured in the Battle of Montevideo. Artigas was taken prisoner, but he managed to escape and returned to the countryside. He organized groups of "gauchos" and began a guerrilla war against the British. The British tried to capture Buenos Aires a second time, but were defeated by the local armies, and returned Montevideo to Spanish control as part of the terms of capitulation. Artigas was promoted to captain in 1809.