José de San Martín and his forces took possession of the city. He proclaimed to the people of Peru:
El Perú es desde este momento libre e independiente por la voluntad de los pueblos y de la justicia de su causa que Dios defiende.
(Peru is from this moment free and independent
by the wish of the people and the justness of the cause which God defends.)
In spite of the disapproval of his supporters in Argentina who had not wished him to take on Peru, San Martín became Protector del Peru and head of the new government which instituted vast social and political reforms, created a national library and a free press. In gratitude for his efforts, the people of Peru gave him the standard Francisco Pizarro had brought from Spain centuries earlier. Royalist supporters staged an offensive which fizzled and after securing the port of Callao, San Martín ordered Admiral Cochrane and the Chilean navy back to Chile. One captain stayed behind and captured the last two remaining Spanish ships, Prueba and Venganza in South American waters. The frigate Prueba was renamed Protector and became the first ship of the Peruvian navy.
Only two Spanish armies remained in South America, one surrounding Quito and the other in the southern regions of Peru. Simón Bolívar sent troops from Colombia to take Quito. They succeeded in May, 1822. Bolívar landed in Guayaquil in July and annexed the territory to Colombia.
Meanwhile, having alienated the royalist factions in Peru and some of the liberals with his intent to create a new monarchy, San Martín was losing political and military strength. He delegated his political power to Don José Bernardo de Tagle, marqués de Torre-Tagle and set his mind to military matters. With combined forces of Argentine, Chilean and Peruvian forces, he faced the Spanish south of Lima and following several battles, some of which he lost, he turned to Simón Bolívar for help.
He offered to become Bolívar's second in command to force Spain out of Peru and South America. Bolívar invited him to a meeting in Quayaquil.
When he arrived in Quayaquil on July 25, 1822, San Martín was feted and honored by the local citizens. He met with Simón Bolívar for about an hour. The next day, after conferring for several hours alone with Bolívar, and after a banquet and ball in his honor, San Martín left the city and returned to Peru.
There are no written records of their discussions, but it is known they discussed independence, the forms of government for the new countries and could not reach agreement. They disliked each other. Speculation has it that Bolívar refused to send his armies to Peru while San Martín was there. A clue to their personality conflict may be found in the toasts they offered at the ball:
Bolívar: Por los dos hombres más grandes de la América del Sud: el General San Martín y Yo.
To the two greatest men in South America: General San Martín and me
San Martín: Por la pronta conclusión de la guerra; por la organización de las diferentes Repúblicas del continente y por la salud del Libertador de Colombia.
To the prompt conclusion of the war, to the organization of the different republics of the continent and to the health of the Liberator of Colombia.
On his return to Peru, San Martín invoked the first Peruvian congress and at the first session, abdicated his powers in a farewell speech. The congress voted him a pension and named him Fundador de la Libertad del Perú. That same day he set sail for Chile and from there continued to Argentina, to his small farm in Mendoza.
Bolívar's forces, under the command of General Sucre, defeated the Spanish royalist forces at the battles of Junín and Ayacucho, completing the liberation of Peru.
In Mendoza, San Martín received news that Bernardo O'Higgins had been forced to resign as the Supreme Director of Chile, and a letter from his wife, Maria de los Remedios, asking him to come to Buenos Aires. They hadn't seen each other for four years, but San Martín delayed for some months before he did as she asked, and it was then too late. She died in August of 1823 of tuberculosis, then called consumption, at the age of twenty-five. During that illness, Remedios left much of the upbringing of her daughter to her parents and young Mercedes was known to be willful and spoiled.

