In 1814, having been instrumental in the establishment of a popularly elected congress in Argentina, José de San Martín began to consider the problem of driving the Spanish royalists from South America entirely. He realized that the first step would be to expel them from Chile, and, to this end, he set about recruiting and equipping an army. In just under two years, he had an army of some 6,000 men, 1,200 horses and 22 cannons. On January 17, 1817, he set out with this force and began the crossing of the Andes. Careful planning on his part had meant that the royalist forces in Chile were deployed to meet threats that did not exist, and his crossing went unopposed. Nonetheless, the Army of the Andes suffered heavy losses during the crossing, losing as much as one-third of its men and more than half of its horses. San Martin found himself allying with Chilean patriot Bernardo O'Higgins, who commanded his own army. The royalists rushed north in response to their approach, and a force of about 1,500 under Brigadier Rafael Maroto blocked San Martin's advance at a valley called Chacabuco, near Santiago. In the face of the disintegration of the royalist forces, Maroto proposed abandoning the capital and retreating southward, where they could hold out and obtain resources for a new campaign. The military conference called by Royal Governor Field Marshal Casimiro Marcó del Pont on February 8 adopted Maroto's strategy, but the following morning, the Captain General changed his mind and ordered Maroto to prepare for battle in Chacabuco. The night before the clash, Antonio de Quintanilla, who would later distinguish himself extraordinarily in the defense of Chiloé, confided to another Spanish official his opinion of the ill-chosen strategy: Given the position of the insurgents, the royalist forces ought to retreat a few leagues towards the hills of Colina. "Maroto overheard this conversation from a nearby chamber and either couldn't or refused to hear me because of his pride and self-importance, called on an attendant with his notorious hoarse voice and proclaimed a general decree on pain of death, to whoever suggested a retreat." All Maroto and his troops had to do was delay San Martin, as he knew that further royalist reinforcements were on the way from Santiago. San Martin was well aware of this as well and opted to attack while he still had the numerical advantage.
Prelude
San Martín received numerous reports of the Spanish plans from a spy dressed as a roto, a poverty-stricken peasant of Chile. The roto told him that the Spanish general, Marcó, knew of fighting in the mountains and told his army to "run to the field", which refers to Chacabuco. He also told San Martín the plan of General Rafael Maroto, the leader of the Talavera Regiment and a force of volunteers of up to 2,000 men. His plan was to take the mountainside and launch an attack against San Martín. On February 11, three days before his planned date of attack, San Martín called a war council to decide on a plan. Their main goal was to take the Chacabuco Ranch, the royalist headquarters, at the bottom of the hills. He decided to split his 2,000 troops into two parts, sending them down two roads on either side of the mountain. The right contingent was led by Miguel Estanislao Soler, and the left by O’Higgins. The plan was for Soler to attack their flanks, while at the same time surrounding their rear guard in order to prevent their retreat. San Martín expected that both leaders would attack at the same time, so the royalists would have to fight a battle on two fronts.
Battle
San Martín sent his troops down the mountain starting at midnight of the 11th to prepare for an attack at dawn. At dawn, his troops were much closer to the royalists than anticipated, but fought hard and heroically. Meanwhile, Soler's troops had to go down a tiny path that proved long and arduous and took longer than expected. General O’Higgins, supposedly seeing his homeland and being overcome with passion, defied the plan of attack and charged, along with his 1,500. What exactly happened in this part of the battle is fiercely debated. O’Higgins claimed that the royalists stopped their retreat and started advancing towards his troops. He said that if he were to lead his men back up the narrow path and retreat, his men would have been decimated, one by one. San Martín saw O’Higgins premature advance and ordered Soler to charge the royalist flank, which took the pressure off O’Higgins and allowed his troops to hold their ground. The ensuing firefight lasted into the afternoon. The tide turned for the Army of the Andes as Soler captured a key royalist artillery point. At this point, the royalists set up a defensive square around the Chacabuco Ranch. O’Higgins charged the center of the royalist position, while Soler got into position behind the royalists, effectively cutting off any chance of retreat. O’Higgins and his men overwhelmed the royalist troops. When they attempted to retreat, Soler's men cut them off and pushed towards the ranch. Hand-to-hand combat ensued in and around the ranch until every royalist soldier was dead or taken captive. 500 royalist soldiers were killed and 600 taken prisoner. The Army of the Andes only lost twelve men in battle, but an additional 120 lost their lives from wounds suffered during the battle. Maroto succeeded in escaping, thanks to the speed of his horse, but was slightly injured.
Aftermath
The remaining royalist troops left Chile and retreated to Lima by ship. Interim governor Francisco Ruiz-Tagle presided at an assembly, which designated San Martín as governor, but he turned down the offer and requested a new assembly, which made O'Higgins Supreme Director of Chile. This marks the beginning of the "Patria Nueva" period in Chile's history.