The Peru–Bolivian Confederation
However, in 1835, Santa Cruz wrote a letter, calling him to arms. In 1833, General Agustín Gamarra had found himself out of favour with the National Congress, which had supported General Luis José de Orbegoso as the former's successor. Gamarra remained in rebellion, however, and headed to Bolivia to request the aid of President Santa Cruz. In 1835, General Felipe Santiago Salaverry rebelled against Orbegoso and successfully ousted him. Although Santa Cruz had actually provided support to Gamarra, in the form of men and money, and had even agreed to the creation of a Peru–Bolivian Confederation, separating Peru between the Republics of North and South Peru, the alliance collapsed.
Gamarra had defeated an army that Salaverry had sent to Cusco to retake the city. In light of this victory, Gamarra broke his agreement with Santa Cruz and aspired to seize the Presidency of Peru for himself. However, he was defeated at the Battle of Yanacocha by Colonel José Ballivián. It was at this point that Santa Cruz entered into an alliance with Orbegoso, with the promise of a Confederation between Peru and Bolivia.
In 1836, O'Connor marched alongside Santa Cruz and the Bolivian Army to the city of Arequipa, where Salaverry and his army were located. When the Bolivian Army entered the city, Salaverry's army was leaving, heading toward Uchumayo. Santa Cruz decided to remain in the city instead of pursuing the enemy, and, on the other side of the river, Salaverry's army rained heavy fire onto the city for six days. On 4 February, General Ballivián led a charge which was completely defeated by Salaverry, with O'Connor's division having to cover for the defeated and retreating first division. On the morning of 7 February, O'Connor spotted Salaverry's army marching toward Huascacachi. Salaverry's intention was to cut off the Bolivian supply, preventing any possible retreat by Santa Cruz into Bolivia. Sensing an opportunity, since the enemy forces were marching in thin files and were not in a position to fight, O'Connor informed Santa Cruz who ordered an immediate attack. A charge led by General Otto Philipp Braun effectively decided the outcome of the so-called Battle of Socabaya, ending in the capture and later execution of Salaverry and several of his officers.
With the new Confederation secured, Santa Cruz made three major mistakes: the annulment of the treaty of peace and friendship with Chile; the promotion of the civilian Mariano Enrique Calvo to Division general; and marginalizing José Miguel de Velasco, who had served loyally under Santa Cruz, which led to his later defection in Tupiza in 1839. O'Connor describes these as "the major blunders which cost Santa Cruz", the first being the anger of the army at the promotion of Calvo:Congress passed a law... which had Doctor Mariano Enrique Calvo, Prosecutor of the Supreme Court and then appointed Vice President of Bolivia, in charge of the Executive Power in the absence of General Santa Cruz, promoted to division general. The soldiers of the army were very offended by the appointment of Calvo, and they told me that they did not want to accept a peso of the money that had been granted to them by Congress, and that they did not approve and could not approve the appointment of a civilian to the rank of division general.The second major blunder which O'Connor describes is the annulment of the treaty with Chile signed under Salaverry, which had led to the declaration of war by said nation:[As for the war with Chile], the cause was the decree passed by General Santa Cruz which annulled the treaty of peace, friendship, and trade concluded between Salaverry, the intrusive president of Peru, and the Government of Chile... and the Captain General [Santa Cruz] knew it and must have weighed on him; however, he was so proud as a result of the victory at Socabaya that he imagined himself in a position to do whatever occurred to him at will, without looking at one side or the other, and this fact, which seemed insignificant to him, was the cause of his downfall and that of all the Confederation.The third major blunder O'Connor mentions is the disrespect toward and marginalization of General Velasco, whose defection in 1839 would be the event which finally toppled Santa Cruz in Bolivia:I received from Lima the plaque of a Great Dignitary of the Legion of Honor of Bolivia, which was worth the pension of five hundred pesos for life. This dignity was not conferred on General Velasco, who had been Vice President of Bolivia for many years, and President also after the death of General Pedro Blanco, on the last night of 1828, and Chief of Staff of the Bolivian Army during the Battle of Yanacocha. Another reckless decision by General Santa Cruz, as this was the real cause behind the defection of General Velasco in Tupiza, and his pronouncement for the Restoration in February 1839, when he learned of the defeat of the Confederation Army in Yungay.The war with Chile continued when Diego Portales was assassinated by his own men, followed by a mutiny in Oruro against Santa Cruz. Sensing an opportunity, the Chileans invaded Peru and were able to occupy the city of Arequipa. The Army of the Confederation far outnumbered that of the Chilean Army in Arequipa. However, instead of achieving a decisive and crushing victory over Chile, Santa Cruz opted for the signing of a peace treaty, known as the Treaty of Paucarpata, celebrated on 17 November 1837. O'Connor vehemently disagreed with such a treaty, telling Santa Cruz that he did not believe the Chilean government would abide by such a treaty. After the treaty was signed, Santa Cruz negotiated with General Manuel Blanco Encalada the sale of all the horses in the Chilean Army in Arequipa, paying very high prices for the time.
The Argentine Confederation under Juan Manuel de Rosas had, like the Chileans, also declared war on Santa Cruz. O’Connor was sent hurriedly to Tarija alongside General Braun to prevent the Argentine army under Gregorio Paz from seizing the province. The Argentines intended to claim the province of Tarija, long disputed with Bolivia. Although the Bolivian high command believed the enemy was located in San Luis, the Argentines were actually advancing toward Tarija. O’Connor and Braun pursued Paz and eventually caught up to his army near the Montenegro mountain range, on the banks of the Bermejo River on 24 June 1838.
The Bolivians led an uphill charge against the Argentines, who were holding a defensive position. Although Paz's men were firing ferociously, the Bolivians under O’Connor led an impressive charge which resulted in the Argentine army abandoning their positions and fleeing to safety. Braun eventually caught up with O’Connor to discover the Argentine troops fleeing and abandoning all their belongings in the process. Thus, the Battle of Montenegro came to an end with a decisive Bolivian victory.
Previously, on 11 June, the second division of the Argentine army, led by Alejandro Heredia, was defeated at the Battle of Iruya, completely repelling the attack of the enemies. When General Heredia was suddenly assassinated, the war on the south essentially ended, with the threat of an Argentine invasion eliminated.
The Chileans were quick to resume hostilities with Santa Cruz, as the so-called treaty of Paucarpata was not ratified by the Chilean government. Landing in Peru, the Restoration Army, composed of Peruvian exiles and Chileans, was able to crush Santa Cruz in the decisive Battle of Yungay, leading to the unravelling of the Confederation. On 9 February 1839, General Velasco proclaimed himself against Santa Cruz, and in the following days the Departments of Chuquisaca, La Paz, and Cochabamba declared themselves in favour of the rebellion. Velasco would erase O'Connor from the military list of Bolivia, resulting in the banishment of the latter from political and military affairs. O'Connor retired to his estate in Tarija, never to offer his services again for any government, especially not Velasco's.