On 7 July 1822 Ballesteros defeated the Royal Guards, preventing a coup against the Constitution. For this he was named Captain General of Madrid. In 1823 he fought the French invasion under Louis-Antoine, Duke of Angoulême in Navarra and Aragón, but he had to capitulate on 21 August 1823 in Caporla.