The history of Pedro II of Brazil in the Paraguayan War began after the invasion of Brazilian provinces by Paraguayan forces by the end of 1864.
In December 1864 the dictator of Paraguay, Francisco Solano López, ordered the capture of the Brazilian civilian steamship Marquês de Olinda, including its passengers and crew. The Paraguayan army invaded the Brazilian province of Mato Grosso (currently the state of Mato Grosso do Sul) immediately afterward without a declaration of war. Four months later, Paraguayan troops also invaded Argentine territory as a prelude to an attack upon the Brazilian province of Rio Grande do Sul. News of the Paraguayan invasions was received with surprise both by the Brazilian government and public. Brazil had previously discounted the war-making potential of neighboring Paraguay. Pedro II, along with most Brazilians, was infuriated at what were seen as unjustified attacks and felt that punitive measures were justified in response. This resolve was strengthened by the Emperor's general antipathy towards all caudillos—dictators who were common elsewhere in Latin America.
Nevertheless, Pedro II tried to pacify the nation in a speech from the throne on 6 May 1865 during which he addressed concerns such as public health, the economy, and the marriages of his daughters. He calmly made only brief mentions of the ongoing conflict with Great Britain and the Paraguayan invasion. He was reluctant for the Empire to become further entangled in the problems of the Platine region, as he affirmed in his diary in 1862: "After the war against Rosas, I was always a partisan for Brazil's abstention from the affairs of the Plata, excepting harm to the national honor and Brazilian interests." Even so, he strongly supported the cabinet in its decision to counterattack.
The invasion of Rio Grande do Sul became known in the capital on 30 June 1865. Aware of the anarchy in the province and the incapacity and incompetence of its military chiefs to resist the Paraguayan army, Pedro II decided to go to the front in person. He wrote to the Countess of Barral: "Rio Grande do Sul has been invaded, my place is there". As Head of State, he intended to assume command of the Brazilian army. Both the Cabinet and the General Assembly refused to accede to the Emperor's wish. The senators and general deputies, using their constitutional prerogatives, refused to grant permission for the travel. If something happened to the Emperor, the throne would be inherited by his 18-year-old daughter Isabel. The risks to the stability of the country were considered too great at that critical moment. After he also received objections from the Council of State, Pedro II made the memorable pronouncement: "If they can prevent me from going as an Emperor, they can not prevent me from abdicating and going as a Fatherland Volunteer". Thus those Brazilians who signed up to go to war under Decree 3,371 of 7 January 1865 became known throughout the nation as the "Fatherland Volunteers." The monarch himself was popularly called the "Number-one Volunteer."
Pedro II left for the south on 7 July 1865 (some authors state instead that he left on 10 July) and was greeted by crowds, along with the national anthem and patriotic celebrations. Accompanying him were his son-in-law the Prince Ludwig August of Saxe-Coburg and Gotha, his Aide-de-camp General Francisco Xavier Calmon Cabral da Silva (later the 2nd Baron of Itapagipe), the Vice Admiral William Parker, the Minister of War Ângelo Ferraz, his Aide-de-Camp the Marquis of Caxias, Admiral Joaquim Raimundo de Lamare, General Beaurepaire-Rohan, and an escort of 300 soldiers. Upon embarking, he said: "I am the perpetual defender of Brazil, and when my fellow citizens sacrifice their lives in holocaust upon the altar of the fatherland in defense of such saintly cause, I will not be the one who refuses to follow them."
Pedro II disembarked in Rio Grande do Sul on 16 July and proceeded from there by land with his escort of 300 men. The trip was made by horse and wagon, and at night the emperor slept in a campaign tent. On 1 August at Caçapava he was joined by his other son-in-law, Gaston d'Orléans, the Count of Eu, who had arrived from Europe where he had been spending his honeymoon. From Caçapava he traveled to São Gabriel, and on 5 September passed through the Campo do Rosário (Field of the Rosary), where 37 years earlier Brazilian troops were defeated by Argentine and Uruguayan forces. General Francisco Xavier Calmon, who had participated in the battle and was traveling with the Emperor, related his memories of the event. In São Gabriel the Emperor said farewell to João Propício Mena Barreto, Baron of São Gabriel, former commander-in-chief of the Brazilian Army during the Uruguayan War, who was dying of tuberculosis. He also visited the hospitals and talked with the wounded. Pedro II also had his first contact with the Paraguayans when he talked with three prisoners of war. He spoke in guarani and offered them an opportunity to return to Paraguay. The Paraguayans refused, alleging that they would be put to death by Lopez for having been taken prisoner. These Paraguayan soldiers, who had hated the monarch without ever having met him, began to admire him greatly and called him Murubichab ("Great Chief" in guarani). The Emperor, for his part, felt pity for the Paraguayan people and was convinced that Lopez’s dictatorship was barbarous and must be overthrown at any cost.
After quickly passing Alegrete Pedro II arrived in Uruguaiana on 11 September, where he joined Admiral Joaquim Marques Lisboa (then Baron of Tamandaré), General João Frederico Caldwell, General Manuel Luis Osório (later Marquis of Erval) and Manuel Marques de Sousa (then Baron of Porto Alegre and also commander of the besieging forces). Uruguaiana had been taken by the Paraguayans under Lieutenant Colonel Antonio de la Cruz Estigarribia with a force of 10,000 men on 5 August 1865. By the time of the Emperor's arrival, Estigarribia's force was reduced to only 5,500 men, while the besieging army composed of Brazilians, Argentines and Uruguayans was 17,000-strong. Pedro II also met the Argentine president Bartolomé Mitre and Uruguayan president Venancio Flores, who were commanding the troops of their respective nations.
A quarrel developed in the allied camp: Mitre demanded supreme command of the allied army in accordance with the Treaty of the Triple Alliance. The Brazilian military leaders refused to accept this, since the same treaty affirmed that on Brazilian soil the command would be held by a Brazilian. Pedro II amicably persuaded all to accept his proposal: the allied forces would be divided in three columns, each under the command of a chief of their own nationality, while he would act as a Moderating Power to mediate conflicts between the three commanders, thus becoming de facto and de jure commander of the allied army. The Emperor rode within rifle shot of Uruguaiana to demonstrate his courage, but the Paraguayans did not attack him.
The strategies proposed by the commanders conflicted: Osório suggested that they should destroy the village using artillery, since all its (Brazilian) inhabitants had run away before it had fallen to the Paraguayans. Tamandaré and Flores, on the other hand, pushed for an initial bombardment followed by an advance of the allied troops. Pedro II wished to prevent the bloodshed of a battle and called on Estigarribia to surrender. Estigarribia did so on the condition that he would surrender only to the Brazilian Emperor, as he did not trust his fellow republicans from Argentina and Uruguay. The Paraguayan troops paraded in front of the allies and the sword of Estigarribia was solemnly delivered by the minister Ferraz to Pedro II. By "his example and his actions he had contributed decisively to the expulsion of the Paraguayan invaders from Brazilian soil." The Paraguayans were malnourished and practically naked. Pedro II did not feel proud of the victory and wrote to the Countess of Barral: "Yesterday we entered into Uruguaiana. The enemy was unworthy even of being defeated. What a rabble!" There was a general belief that the war was near its end and that it was only a matter of time until López surrendered. Because of this, Pedro II decided to return to Rio de Janeiro. Before leaving Uruguaiana, he received the British ambassador Edward Thornton, who publicly apologized on behalf of Queen Victoria and the British Government for the crisis between the empires. The emperor considered that this diplomatic victory over the most powerful nation of the world was sufficient and renewed friendly relations between the nations. He returned to Rio de Janeiro and was received with great joy and celebration everywhere.
The war's cost came to R$614.000:000$000 (see Brazilian currency), which was paid as follows: R$265.000:000$000 from taxes, R$171.000:000$000 from bond sales, R$102.000:000$000 in new money issued, R$27.000:000$000 from internal loans and R$49.000:000$000 from foreign loans. Thus, only 7.9% of the total war debt was composed of external loans. However, Brazil was so prosperous that the government retired the war debt in only ten years. The conflict was a stimulus to national production and economic growth. After more than five years of war, the emperor seemed to have aged twenty years: his blond hair and beard had become completely grey and at age 44 his face seemed to be of a sexagenarian. Pedro II's popularity, which had suffered during the long conflict, immediately recovered upon final victory. The Emperor turned down the General Assembly's suggestion to erect an equestrian statue of him to commemorate the victory and chose instead to use the money to build elementary schools.