By the 1840s a significant proportion of the enlisted men in the United States Army were Catholic immigrants from Ireland and Germany. The Mexican government, aware of prejudice against immigrants to the United States, started a campaign after the Mexican War broke out to win the foreigners and Catholics to its cause. The Mexicans urged English and Irish alike to throw off the burden of fighting for the "Protestant tyrants" and join the Mexicans in driving the Yankees out of Mexico. Mexican propaganda insinuated that the United States intended to destroy Catholicism in Mexico, and if Catholic soldiers fought on the side of the Americans, they would be warring against their own religion. Using this approach, the Mexicans hoped to gain 3,000 soldiers from the United States Army. In November 1846 Gen. Antonio López de Santa Anna organized American deserters with other foreigners in Mexico to form the San Patricio Battalion, or St. Patrick's Company, a name it probably received from its Irish-American leader, John Riley, formerly a member of Company K of the Fifth United States Infantry. The company saw action at Monterrey, again near Saltillo, and at Buena Vista, each time receiving praise for its thorough job. The most important conflict came at the battle of Churubusco in August 1847.
By July 1, 1847, Santa Anna gathered enough deserters and foreigners to organize two San Patricio battalions of 100 men each. As American forces rapidly approached Mexico City, Santa Anna divided his forces into three armies to guard several entrances to the city. One of these, commanded by Gen. Gabriel Valencia, was surprised by the Americans at Contreras and defeated. Santa Anna then decided to concentrate his forces at Churubusco, where there was a fortified bridgehead and a Franciscan convent. He stationed the San Patricio companies with a battery of five cannons on the bridge. The American forces advanced from the south and the west covering one side of the fort. Although they suffered heavy casualties, the Americans continued to advance. Suddenly they noticed a drop in gun fire as they made their cautious approach. With his supplies running low, Santa Anna now ordered one company of San Patricios into the fort, along with another infantry company and a wagon of ammunition. The cartridges in the wagon, however, were the wrong caliber for all the weapons except those used by the San Patricios. From inside the fort the San Patricios manned three of the seven cannons. (Later some said that their gunfire was aimed at former officers.) The Americans continued to press on, forcing the second company of San Patricios and other Mexican soldiers into the convent. Reportedly, Mexican soldiers inside the convent tried three times to raise the white flag, but the San Patricios, desperate because of their fate if captured, tore it down. At last Capt. James M. Smith of the Third Infantry entered and put his own handkerchief on the pole. Once back with the United States Army, the San Patricio company did not fare well. Gen. Winfield Scott issued General Orders 259 and 263 establishing two courts martial for seventy-two deserters. Col. John Garland convened the first court martial on August 23, 1847, in Tacubaya. Col. Bennet Riley, an Irish Catholic officer, convened the second court martial at San Angel on August 26. Only two defendants did not receive the death sentence, one excused because of improper enlistment in the United States Army, the other because he was deemed insane.
When General Scott received the verdicts for approval, the Mexican people faced him with cries of outrage at the treatment of their soldiers. After considering appeals from the archbishop of Mexico, the British minister to Mexico, and a number of foreign citizens resident in Mexico City (including United States citizens), Scott reevaluated the courts martial, giving close attention to the Articles of War. Scott issued General Order 281 on September 8, 1847, and out of the twenty-nine men tried at San Angel, twenty received the death sentence. John Riley, the leader, technically deserted before the war between Mexico and the United States was declared, so he could not be hanged. He received fifty lashes and the letter "D" branded on his cheek. Scott issued General Order 283 several days later concerning the trials at Tacubaya, confirming the death sentence for thirty San Patricios, and allowing the same considerations he had with the group before. Several of the men received pardon due to their relatively young age; and one man was pardoned because he was not a willing deserter, but had been kidnapped by the Mexicans while he was drunk. Sentences for the men tried at San Angel were carried out in that village on September 10; sentences from Tacubaya were executed in the village of Mixcoac on September 13. The latter sentences were carried out under the command of Col. William S. Harney, who had the condemned men fitted with nooses at daybreak and then left them standing on the gallows while the battle for Chapultepec Castle raged nearby. The men were to be hanged when the United States flag was raised over the castle; United States troops took Chapultepec several hours later, at 9:30 a.m. The sentences imposed on the San Patricios outraged the Mexican public. In Toluca Mexican authorities prevented rioters from trying to retaliate against American prisoners of war.
This did not end the story of the San Patricios. Mexico continued its dubious recruitment of deserters and by March of 1848 had found enough original San Patricios and new deserters to form two more companies. Mexico did not forget its San Patricios still held by American authorities and continued bargaining for their release. However, it wasn't until the Treaty of Guadalupe Hidalgo was signed, and the war ended, that the fourteen remaining prisoners were released. The San Patricios continued as a group, providing support by patrolling areas of Mexico to protect the people from bandits and Indians. They later became involved in revolts within Mexico until a presidential order of General Herrera stopped them. Under the order, Riley was arrested for suspicion of a plot to kidnap President José Joaquín de Herrera, and the San Patricios were recalled to Mexico City where the government could monitor their actions. Herrera, in order to end the problems with the San Patricios and dispel any further crises as well as to cut the postwar budget, dissolved the company in 1848, a short time after it received its last military expenditure in August. While some members of the San Patricio company petitioned the government of Mexico for help in returning to their European homelands, most remained in Mexico as they could not return to the United States.