Beyond Moquegua the ground rises in abrupt steps which give great facilities for defence. The Royalist skirmishers covered the heights, and detached parties lay in ambush in the hollows. One by one they were driven from these positions, but at Torata Valdés drew up his force in line of battle. On the afternoon of the 19th the two armies faced each other, and the Patriots advanced to the attack. A Spanish battalion in skirmishing order covered the centre, and at the same moment the heights beyond were occupied by an advanced party of Canterac’s division, whose shouts of “Viva el Rey!” re-echoed from the mountain sides. Canterac strengthened his right flank and beat back a vigorous attack of the left wing of the Patriots, upon which the whole Royalist line advanced and drove the Patriot infantry, who had exhausted their ammunition, before them in utter rout with great slaughter. The Patriots lost about 500 men killed and wounded, the Royalists about half that number. The Peruvian legion, which was now for the first time under fire, distinguished itself by its steady behaviour.

The routed battalions rallied under the fire of their artillery, but during the following night the whole army retreated, and encamped next day at Moquegua, seventeen miles from the field of battle. The ammunition was nearly exhausted. Alvarado summoned a council of war, but the advice of his officers was so discordant, that before he had formed any resolution the enemy was again in his front on the 21st.

Alvarado then took up a strong position, with his left resting upon the suburbs of the city, and his line extending along the ridge of a steep declivity, broken in the centre by a road which was swept by the fire of his artillery. His right rested upon a bare hill. Valdés, with two battalions and two squadrons of horse, seized this hill and turned the right flank of the Patriots, while the rest of the Royalist cavalry menaced the left, and Canterac led the main body against the ridge. Alvarado wheeled back his right wing, and for a short time the Patriots held their ground with great determination, but were at length driven from the position and totally routed with a loss of 700 in killed and wounded, and 1,000 prisoners. The mounted grenadiers, led by Lavalle, made two desperate charges to cover the retreat, but were in their turn overwhelmed by the Royalist horse.

About 1,000 men reached Ilo with General Martinez, and embarking there, returned to Lima. Alvarado went to Iquiqui in search of the detachment he had left there, and on the 14th February landed a small party on shore, which was all either captured or destroyed by Olañeta, who had occupied the city. Alvarado then invited Olañeta to a conference concerning the prisoners, and found this general to be so disaffected to the Viceroy and his adherents, whom he styled “traitorous Liberals,” that he declared his intention of separating from them and confining himself to the defence of Upper Peru for the King.

Miller, with his 120 men, accomplished more than all the rest of the army; he alarmed all the South, and kept the whole reserve under Caratala in check.

Meantime Arenales lost much time in endeavouring to persuade General Castillo to incorporate his auxiliaries with the army he was organizing for the attack on the centre of the Royalists. Castillo refused to join at first, on the plea that success was doubtful, and then demanded that a Peruvian should be appointed to command the allied army. His demand being refused, he then asked permission to retire altogether from the country. Government, anxious to free itself from so arrogant an ally, furnished transports, and the Columbian contingent left Peru for Guayaquil, taking with it the Numancia battalion, 600 strong, which Bolívar had claimed, as being a Columbian corps. This Columbian contingent had cost Peru 190,000 dollars and had been of no service whatever.

Nevertheless Arenales, who hoped to make up by speed for paucity of numbers, had organized a column of 2,000 men, when Martinez arrived with a remnant of the Army of the South. The news brought by him produced great irritation, but by no means disheartened the people, who were confident of ultimate success. Their anger was turned against Government; the army encamped at Miraflores was almost in open revolt. Arenales was asked to put himself at the head of the movement, but this stout soldier would have none of it, and giving up the command to Santa Cruz left Peru for ever.

The leaders of the army headed by General Martinez, on the 26th February, 1823, presented an address to Congress, asking that Riva-Agüero might be placed at the head of the Executive. The city militia supported them. Congress yielded, and on the 27th Riva-Agüero was named President of the Republic, and afterwards Grand Marshal of the armies, although he was simply a colonel of militia and had never been under fire.

Riva-Agüero was a true representative of the people, and his popularity was enhanced by his activity and by the skill shown in the first measures he adopted. He reorganized the army, making Santa Cruz general-in-chief, and Martinez general of the division of the Andes and Chile. He reopened relations with Chile, and wrote to Bolívar accepting the help which Congress had refused. Bolívar made a treaty with him, in which he promised 6,000 men, who were to be equipped and paid by Peru. Chile promised a further contingent of from 2,000 to 2,500 men, and 1,500 muskets in addition. San Martin in Mendoza pushed on the organization of an Argentine division, which was to operate on the frontiers of Salta, under the orders of Urdininea. At the same time news was received that the Peruvian commissioners, in London, had abandoned their monarchical schemes, and had effected a loan of one million two hundred thousand pounds sterling, which was ratified by Congress.

Before two months had passed Peru had an army of 5,000 men ready for the field, in addition to the Argentine and Chilian auxiliaries, who were 2,500 more. Riva-Agüero determined upon another expedition to the intermediate ports, directed against Arequipa and Puno, while another army, composed of troops of the four Allied Nations, should advance by Jauja upon the centre, a repetition of the previous plan. Bolívar approved of the plan when his opinion was asked, and promised his 6,000 men. Chile again promised a fresh contingent, which should be sent to the south of Peru, and offered to supply horses for the expedition. The Royalists, ignorant of these preparations, made ready on their part for an attack upon Lima.