A disagreement with Peru in 1828 resulted in the invasion of Ecuador and the temporary occupation of Cuenca and Guayaquil by Peruvian forces; but peace was restored in the following year after the Ecuadorian victory at Tarqui. In the early part of 1830 a separation was effected from the Colombian federation, and the country was proclaimed an independent republic. General Juan José Flores was the first president, and in spite of many difficulties, both domestic and foreign, he managed to maintain a powerful position in the state for about 15 years. Succeeded in 1835 by Vicente Rocafuerte, he regained the presidency in 1839, and was elected for the third time in 1843; but shortly afterwards he accepted the title of generalissimo and a sum of 20,000 pesos, and left the country to his rivals. One of the most important measures of his second presidency was the establishment of peace and friendship with Spain. Roca, who next attained to power, effected a temporary settlement with Colombia, concluded a convention with England against the slave trade, and made a commercial treaty with Belgium. Diego Noboa, elected in 1850 after a period of great confusion, recalled the Jesuits, produced a rupture with New Granada by receiving conservative refugees, and thus brought about his own deposition and exile. The democratic Urbina now became practically dictator, and as the attempt of Flores to reinstate Noboa proved a total failure, he was quickly succeeded in 1856 by General Francisco Robles, who, among other progressive measures, secured the adoption of the French system of coinage, weights and measures. He abdicated in 1859 and left the country, after refusing to ratify the treaty with Peru, by which the defender of Guayaquil had obtained the raising of the siege. Dr Gabriel Garcia Moreno, professor of chemistry, the recognized leader of the conservative party at Quito, was ultimately elected by the national convention of 1861. Distrust in his policy, however, was excited by the publication of some of his private correspondence, in which he spoke favourably of a French protectorate, and the army which he sent under Flores to resist the encroachments of Mosquera, the president of New Granada, was completely routed. His first resignation in 1864 was refused; but the despotic acts by which he sought to establish a dictatorship only embittered his opponents, and in September 1865 he retired from office. While he had endeavoured to develop the material resources of the country, he had at the same time introduced retrograde measures in regard to religion and education. The principal event in the short presidency of his successor, Gerónimo Carrion (May 1865-Nov. 1867), was the alliance with Chile and Peru against Spain, and the banishment of all Spanish subjects. Several important changes were made by congress in the period between his resignation and the election of Xavier Espinosa, January 1868: the power of the president to imprison persons regarded as dangerous to public order was annulled; and the immediate naturalization of Bolivians, Chilians, Peruvians and Colombians was authorized. Espinosa had hardly entered on his office when, in August 1868, the country was visited by an earthquake, in which 30,000 people are said to have perished throughout South America. The public buildings of Quito were laid in ruins; and Ibarra, Otavalo, Cotacachi and several other towns were completely destroyed. Next year a revolution at Quito, under Moreno, brought Espinosa's presidency to a close; and though the national convention appointed Carvajal to the vacant office, Moreno succeeded in securing his own election in 1870 for a term of six years. His policy had undergone no alteration since 1865: the same persistent endeavour was made to establish a religious despotism, in which the supremacy of the president should be subordinate only to the higher supremacy of the clergy.